2.0.0 • Published 4 years ago

enforced-assertions v2.0.0

Weekly downloads
4
License
MIT
Repository
github
Last release
4 years ago

enforced-assertions

Build Status codecov Maintainability Packages npm version

A simple lib to enforce the assertion of any stub created. Intended to be used with mocha, sinon, chai triad

How it works

Just insert the following command inside the callback of the describe you want to enforce, as the first command:

enforceStubsAssertions(sinon, chai);

You can also call this line in a setup file of the tests outside any describe, so, all your tests will have this enforcing. With this, if you declare a stub, you need to test it in an assertion or your test will throw an error.

After all, if you'll not test your stub, why did you stub it at all? The idea of this package is that, probably, the lack of a assertion for a specific stub may be covering an unexpected behavior.

For this to work, the assertion must be something like this:

expect(myStub)... your assertion here ...

You can accomplish this using libs like sinon-chai, or sinon-chai-calls-assertion

Something like this will not be detected:

expect(myStub.callcout).to.be.eq(1);

I'm really sorry, I did try to make it work with all possible assertions, but I couldn't achieve it, so, if you like the idea of this package, for now, something like the first example will be needed.

Example with sinon-chai:

expect(myStub).to.have.been.calledOnce;

Example with sinon-chai-calls-assertion:

expect(myStub).to.have.callsLike([])
2.0.0

4 years ago

1.3.0

4 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago