Created
October 17, 2012 06:49
-
-
Save froots/3904080 to your computer and use it in GitHub Desktop.
Example of desired behaviour of SinonJS onlyWithArgs() method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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