I have just found about the Jasmine Framework, I am trying it out and though I should try writing a custom matcher, because it sounds extremely useful to be able to do. I did this:
describe('Hello World', function() {
beforeEach(function() {
this.addMatchers({
toBeDivisbleByTwo: function() {
var result = {
pass: (this.actual % 2) === 0
};
if(result.pass) {
result.message = 'this is divisible by two';
} else {
result.message = 'this is not divisible by two';
}
return result;
}
});
});
});
describe('Hello world', function() {
it('divisible by two', function() {
expect(evenNumberGenerator()).toBeDivisbleByTwo();
});
});
but when I run the page I get this error in internet explorer:
TypeError: Object doesn't support property or method 'toBeDivisbleByTwo'
is this due to the order of loading or something?
beforeEachis in a different suite from where you're usingtoBeDivisibleByTwo. Is that a problem? If you move yourbeforeEachout of its containing suite into top-level runner code, does that fix the problem?