Reputation: 817
I'm using protractor with jasmine 1.3, tried adding a custom matcher to my spec using the example here
beforeEach(function () {
utils.log("beforeEach");
this.addMatchers({
toBeGoofy: function (expected) {
if (expected === undefined) {
expected = '';
}
var pass = this.actual.hyuk === "gawrsh" + expected;
if (pass) {
this.message = "Expected " + this.actual + " not to be quite so goofy";
} else {
this.message = "Expected " + this.actual + " to be goofy, but it was not very goofy";
}
return pass;
},
});
});
note that I didn't change anything from their example. after that, i try using it inside an "it" like that:
expect({ "hyuk": "j" }).toBeGoofy();
and i get an error:
TypeError: undefined is not a function
on the line that the matcher was used on.. any help?
Upvotes: 1
Views: 155
Reputation: 817
The problem was the matcher definition apparently. instead of:
if (pass) {
this.message = "Expected " + this.actual + " not to be quite so goofy";
} else {
this.message = "Expected " + this.actual + " to be goofy, but it was not very goofy";
}
this message should be an array of 2 messages, first for pass, second for not.matcher so it would be something like this:
this.message = function() {
return [
"Expected " + this.actual.hyuk + " to be gawrsh",
"Expected " + this.actual.hyuk + " not to be gawrsh"
];
};
Upvotes: 1