Skip to content

Instantly share code, notes, and snippets.

@peteygao
Last active January 3, 2016 10:19
Show Gist options
  • Save peteygao/8448895 to your computer and use it in GitHub Desktop.
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
// 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