Hello,
I've been searching the group for some advice about adding custom matchers in Jasmine 2.1.3, and because i guess the problem may be specific to my situation, here's what i've done.
this is the matcher;
this.addMatchers({
toBeAGoodInvestment = function () {
var investment = this.actual;
return investment.isGood();
};
});
for clarification isGood() is a prototype function of the Investment class. it returns good if an investment increases in stockPrice.
the expectation is written like this
expect(investment).toBeAGoodInvestment();
I tried to add the Matcher in the SpecHelper.js file, when I tried running the SpecHelper page, it through up an error saying
expect(...).toBePlaying is not a function in file:///H:/njs236/Desktop/GitHub/rocketreading/spec/PlayerSpec.js (entirely unrelated to the function that I'm trying to implement.
So I removed it from there, and the other Matcher ran as it should.
Then I put it in a beforeEach = function () in the actual spec file. Whenever I do this it removes the set of tests run from SpecHelper.html
I looked at the advice of someone from the group, to put a reference to the Custom Matcher in the spec, but it doesn't show up when you run the page.
If I disable the toBePlaying custom Matcher in SpecHelper.js and don't have the toBeAGoodInvestment function, when I run the page it says
expect(...).toBeAGoodInvestment is not a function in file:///H:/njs236/Desktop/GitHub/rocketreading/spec/InvestmentSpec.js
obviously this is the only situation where any seem to work together (but the tests fail)
if I put it in the InvestmentSpec.js file, it won't display any tests that are given in this file.
Looking forward to hearing your thoughts.
Nathan