Skip to content

Instantly share code, notes, and snippets.

@danielpsf
Created March 6, 2014 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielpsf/9396450 to your computer and use it in GitHub Desktop.
Save danielpsf/9396450 to your computer and use it in GitHub Desktop.
This is my jasmine spec helper
'use strict';
beforeEach(function() {
this.addMatchers({
toEqualData: function(expected) {
this.message = function () {
var notText = this.isNot ? " not" : "";
return "Expected " + JSON.stringify(this.actual) + notText + " to be equals that " + JSON.stringify(expected);
}
return JSON.stringify(this.actual) === JSON.stringify(expected);
},
toHaveThisPattern : function(expected) {
this.message = function() {
var notText = this.isNot ? " not" : "";
return "Expected " + this.actual + notText + " to have this pattern " + expected;
}
return this.actual.test(expected);
},
toHaveBeenCalledToManyCalls : function(expected) {
this.message = function() {
var notText = this.isNot ? "not" : "";
return "Expected " + this.actual.callCount + notText + " but got " + expected;
}
return this.actual.callCount === expected;
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment