Last active
August 29, 2015 14:20
-
-
Save ahirschberg/8670cbe4401247c80fe0 to your computer and use it in GitHub Desktop.
Sinon mocking strings and integers
This file contains hidden or 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
| // 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) | |
| */ |
This file contains hidden or 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
| // 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