Unexpected call: test(1234) Expected test(1234) once (never called)on our tests, where the first line is what was actually called, and the second line is what was expected. They appear identical.
Here's some tests that illustrate what the problem is:
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! | |
*/ |
Can you spot the difference? It turns out that the id field in the book object is actually a string, and not an integer! Obviously the error output is just converting all the arguments to strings before outputting, and so there's no way to tell what type they are just by looking at the output. To fix this, I'll add a test to the
Book
object to ensure that it converts strings passed in to integers and update the relevant lines in app.js.It really annoys me that such a silly thing took up so much of my time though.
No comments:
Post a Comment