Skip to content

Instantly share code, notes, and snippets.

@ahirschberg
Last active August 29, 2015 14:20
Show Gist options
  • Select an option

  • Save ahirschberg/8670cbe4401247c80fe0 to your computer and use it in GitHub Desktop.

Select an option

Save ahirschberg/8670cbe4401247c80fe0 to your computer and use it in GitHub Desktop.
Sinon mocking strings and integers
// FAILING TEST
describe('#test', function () {
it('tests args', function () {
storageMock.expects('test').once().withExactArgs(1234);
storageManager.otherFunctionThatCallsTest(chapter_obj.id); // should call #test with args: 1234
storageMock.verify();
});
});
/* Console Output:
* Unexpected call: test(1234)
* Expected test(1234) once (never called)
*/
// PASSING TEST
describe('#test', function () {
it('tests args', function () {
storageMock.expects('test').once().withExactArgs('1234');
storageManager.otherFunctionThatCallsTest(chapter_obj.id); // should call #test with args: 1234
storageMock.verify();
});
});
/* Console Output:
* ... SUCCESS!
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment