Skip to content

Instantly share code, notes, and snippets.

@DavidFrahm
Last active August 29, 2015 14:02
Show Gist options
  • Save DavidFrahm/f473b9a4d1369dbff993 to your computer and use it in GitHub Desktop.
Save DavidFrahm/f473b9a4d1369dbff993 to your computer and use it in GitHub Desktop.
Jasmine 1.3.x custom matchers, both global and scoped to a specific describe suite
"use strict";
describe("Jasmine", function () {
describe("custom matchers", function () {
beforeEach(function () {
this.addMatchers({
toBeSomethingBeforeEachInSpec: function (expected) {
return this.actual.something === "something";
}
});
});
it("should work with custom matchers in this spec", function () {
var myObject = {something: "something"};
expect(myObject).toBeSomethingBeforeEachInSpec('param, in spec');
});
it("should work with global custom matchers", function () {
var myObject = {something: "something"};
expect(myObject).toBeSomethingBeforeEachGlobal('param, in global');
});
});
});
"use strict";
beforeEach(function () {
this.addMatchers({
toBeSomethingBeforeEachGlobal: function (expected) {
return this.actual.something === "something";
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment