enforced-assertions
v2.0.0
Published
A simple assertion to validate many aspects of stub calls. It is supposed to use with sinon + chai.
Downloads
18
Maintainers
Readme
enforced-assertions
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([])