Skip to content
/ nonmock Public

Helper library for javascript function replacement in tests or specs

License

Notifications You must be signed in to change notification settings

dmskr/nonmock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NonMock CircleCI Build Status

We don't need a mocks and stubs in javascript, just a little help with replacing existing functions and restoring them back. NonMock helps with function replacing in javascript specs and tests

var monkey = {
  collectBananas: function() {
    console.log('Love Bananas!');
  }
}
module.exports = monkey;
var nonmock = require('nonmock');
var monkey = require('./monkey');
var should = require('chai').should();

describe('monkey', function() {
  it('should love bananas', function(done) {
    nonmock.replace(console, 'log', function(message) {
      message.should.eql('Love Bananas!');
      done();
    });
    monkey.collectBananas();
  })
})

afterEach(function() {
  nonmock.restore();
})

Notice: nonmock.restore() will return back the original console.log once the test finishes

About

Helper library for javascript function replacement in tests or specs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published