Jasmine 2.0 Test With A Custom Matcher Fails: Undefined Is Not A Function
I have this function in my source file: function gimmeANumber(){ var x = 4; return x; } And a spec borrowed from this tutorial describe('Hello world', function() { be
Solution 1:
The API for adding custom matchers has changed since 1.3. You can see the changes here.
Here is how it works now:
functiongimmeANumber() {
var x = 4;
return x;
}
describe('Hello world', function () {
beforeEach(function () {
jasmine.addMatchers({
toBeDivisibleByTwo: function () {
return {
compare: function (actual, expected) {
return {
pass: (actual % 2) === 0
};
}
};
}
});
});
it('is divisible by 2', function () {
expect(gimmeANumber()).toBeDivisibleByTwo();
expect(5).not.toBeDivisibleByTwo();
});
});
Post a Comment for "Jasmine 2.0 Test With A Custom Matcher Fails: Undefined Is Not A Function"