Last active
January 3, 2016 10:19
-
-
Save peteygao/8448895 to your computer and use it in GitHub Desktop.
Jasmine testing pitfall: .join(', ') joins properties that Jasmine has injected into the prototypical inheritance chain
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
// List of badly formatted emails | |
var _badEmails = ['bad@email', 'roar@me']; | |
var _validationMessage = 'Invalid emails: ' + badEmails.join(', '); | |
// _validationMessage should be: 'Invalid emails: bad@email, roar@me' | |
expect(_validationMessage).toBe('Invalid emails: ' + _badEmails.join(', ') | |
// However, the expect statement fails as validationMessage becomes: | |
'Invalid emails: bad@emails, roar@me, function () { | |
spyObj.wasCalled = true; | |
spyObj.callCount++; | |
var args = jasmine.util.argsToArray(arguments); | |
spyObj.mostRecentCall.object = this; | |
spyObj.mostRecentCall.args = args; | |
spyObj.argsForCall.push(args); | |
spyObj.calls.push({object: this, args: args}); | |
return spyObj.plan.apply(this, arguments); | |
}' | |
// Note how the jasmine Spy methods have been join together by .join(', '). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment