sinonquire
Automatically stubs CommonJS modules returned by require/import using Sinon.JS
Inspired by Jest's "mock by default" concept.
Installation
npm install --save sinonquire
Usage
The following example uses mocha, chai and sinon-chai.
First, let's tell sinonquire which paths should never be loaded as stubs.
test/index.js
:
; sinonquire;
Then, make sure this configuration module is started before all the tests.
One way to do it is using the --require
argument of mocha CLI.
package.json
:
"scripts":
OK. Now suppose your app has two main modules, one is a class and the other is a function that instantiate the class a couple of times.
Based on this Jest example.
lib/User.js
:
{ thisname = name; } { return thisname; }
lib/createCouple.js
:
; { const userA = ; userA; const userB = ; userB; return userA userB;}
test/createCouple.js
:
;; ;