Skip to content

stateless utilities for managing mocks and stubs in your node tests

License

Notifications You must be signed in to change notification settings

cyrfer/sinon-mocker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sinon-mocker

stateless utilities for managing mocks and stubs in your node tests

Install

npm install -D sinon-mocker

Example

const SomeModule = require('./a-module');
const lib = require('sinon-mocker');

const assert = require('chai').assert;
const sinon = require('sinon');

// create your testing mocks
const mocks = {
    SomeClass: {
        someMethod: sinon.mock()
    }
};

// know the state of your testing mocks
const stubs = {
    SomeClass: sinon.stub(SomeModule, 'SomeClass').callsFake(lib.fakeCtor(mocks.SomeClass)),
};

// test your code
const test1 = new SomeModule.SomeClass();
test1.someMethod();
assert.equal(mocks.SomeClass.someMethod.callCount, 1, 'did not invoke mocks');

// reset state of your tests
lib.resetMocks(mocks);
lib.restoreServices(stubs);
assert.equal(mocks.SomeClass.someMethod.callCount, 0, 'did not reset mocks');

About

stateless utilities for managing mocks and stubs in your node tests

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published