I tried making some custom matchers globally available by extending
jasmine.Matchers.prototype, as described here:
http://testdrivenwebsites.com/2010/08/04/custom-jquery-matchers-in-jasmine/
What I'm finding is that my matchers always pass when I define them
globally this way, though they work as expected if I used
this.addMatchers() instead.
A repro is below. Two matchers are defined, which should always
fail. Only the second one will actually fail though. The failure
output indicates I'm running Jasmine rc1, I just grabbed the Jasmine
1.0 release and have the same issue.
jasmine.Matchers.prototype.isFailSample = function() {
return false;
};
describe("custom matchers", function() {
beforeEach(function() {
this.addMatchers({
isFailSampleInline: function() { return false; }
});
});
it("this test passes... it shouldnt", function() {
expect(1).isFailSample();
expect(1).not.isFailSample();
});
it("this test fails, as expected", function() {
expect(1).isFailSampleInline();
expect(1).not.isFailSampleInline();
});
});
test output:
custom matchers
runthis test passes... it shouldnt
runthis test fails, as expected
Expected 1 is fail sample inline.
Error("Expected 1 is fail sample inline.")@:0 ([object Object])@http://
canvas/js/lib/jasmine-1.0.0.rc1/jasmine.js:94 ()@
http://canvas/js/lib/
jasmine-1.0.0.rc1/jasmine.js:1143 ()@
http://canvas/js/TestUtilities/
CustomJasmineMatchers.tests.js:22 ((function () {if
(jasmine.Queue.LOOP_DONT_RECURSE && calledS