Skip to content

Instantly share code, notes, and snippets.

@froots
Created October 17, 2012 06:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save froots/3904080 to your computer and use it in GitHub Desktop.
Save froots/3904080 to your computer and use it in GitHub Desktop.
Example of desired behaviour of SinonJS onlyWithArgs() method
beforeEach(function() {
global.fs = require('fs');
sinon.stub(fs, 'readFileSync').onlyWithArgs('my-file.txt').returns('Contents of file');
// Then require the module under test, which uses fs.readFileSync() internally
// require() uses original method with correct calling context
global.myModule = require('../src/my-module');
});
it('does something with the file', function() {
expect(myModule.loadFromFile()).toEqual('Contents of file');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment