enforced-assertions
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

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([])

Dependencies (3)

Dev Dependencies (3)

Package Sidebar

Install

npm i enforced-assertions

Weekly Downloads

2

Version

2.0.0

License

MIT

Unpacked Size

6.78 kB

Total Files

8

Last publish

Collaborators

  • farenheith