Matchers can have a negativeCompare

- Passing in a 'negativeCompare' will cause that function to be used when it is a 'not' assertion
- Otherwise, the reversal of the compare's result will be used instead

[finishes #59703824]
This commit is contained in:
Kyriacos Souroullas and Sheel Choksi
2013-10-28 15:26:48 -07:00
parent e346e7dcc1
commit cd9d5284cd
3 changed files with 107 additions and 3 deletions

View File

@@ -22,12 +22,21 @@ getJasmineRequireObj().Expectation = function() {
args.unshift(this.actual);
var result = matcherFactory(this.util, this.customEqualityTesters).compare.apply(null, args);
var matcher = matcherFactory(this.util, this.customEqualityTesters),
matcherCompare = matcher.compare;
function defaultNegativeCompare() {
var result = matcher.compare.apply(null, args);
result.pass = !result.pass;
return result;
}
if (this.isNot) {
result.pass = !result.pass;
matcherCompare = matcher.negativeCompare || defaultNegativeCompare;
}
var result = matcherCompare.apply(null, args);
if (!result.pass) {
if (!result.message) {
args.unshift(this.isNot);