Added toBeLessThan and toBeGreaterThan matchers.
This commit is contained in:
@@ -1148,6 +1148,16 @@ jasmine.Matchers.prototype.toNotContain = function(item) {
|
|||||||
'Expected ' + jasmine.Matchers.pp(this.actual) + ' not to contain ' + jasmine.Matchers.pp(item) + ', but it does.');
|
'Expected ' + jasmine.Matchers.pp(this.actual) + ' not to contain ' + jasmine.Matchers.pp(item) + ', but it does.');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
jasmine.Matchers.prototype.toBeLessThan = function(expected) {
|
||||||
|
return this.report(this.actual < expected,
|
||||||
|
'Expected ' + jasmine.Matchers.pp(this.actual) + ' to be less than ' + jasmine.Matchers.pp(expected) + ', but it was not.');
|
||||||
|
}
|
||||||
|
|
||||||
|
jasmine.Matchers.prototype.toBeGreaterThan = function(expected) {
|
||||||
|
return this.report(this.actual > expected,
|
||||||
|
'Expected ' + jasmine.Matchers.pp(this.actual) + ' to be greater than ' + jasmine.Matchers.pp(expected) + ', but it was not.');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Matcher that checks that the expected exception was thrown by the actual.
|
* Matcher that checks that the expected exception was thrown by the actual.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -167,6 +167,18 @@ describe("jasmine.Matchers", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("toBeLessThan should pass if actual is less than expected", function() {
|
||||||
|
expect(match(37).toBeLessThan(42)).toEqual(true);
|
||||||
|
expect(match(37).toBeLessThan(-42)).toEqual(false);
|
||||||
|
expect(match(37).toBeLessThan(37)).toEqual(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("toBeGreaterThan should pass if actual is greater than expected", function() {
|
||||||
|
expect(match(37).toBeGreaterThan(42)).toEqual(false);
|
||||||
|
expect(match(37).toBeGreaterThan(-42)).toEqual(true);
|
||||||
|
expect(match(37).toBeGreaterThan(37)).toEqual(false);
|
||||||
|
});
|
||||||
|
|
||||||
it("toThrow", function() {
|
it("toThrow", function() {
|
||||||
var expected = new jasmine.Matchers(env, function() {
|
var expected = new jasmine.Matchers(env, function() {
|
||||||
throw new Error("Fake Error");
|
throw new Error("Fake Error");
|
||||||
|
|||||||
@@ -216,6 +216,16 @@ jasmine.Matchers.prototype.toNotContain = function(item) {
|
|||||||
'Expected ' + jasmine.Matchers.pp(this.actual) + ' not to contain ' + jasmine.Matchers.pp(item) + ', but it does.');
|
'Expected ' + jasmine.Matchers.pp(this.actual) + ' not to contain ' + jasmine.Matchers.pp(item) + ', but it does.');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
jasmine.Matchers.prototype.toBeLessThan = function(expected) {
|
||||||
|
return this.report(this.actual < expected,
|
||||||
|
'Expected ' + jasmine.Matchers.pp(this.actual) + ' to be less than ' + jasmine.Matchers.pp(expected) + ', but it was not.');
|
||||||
|
}
|
||||||
|
|
||||||
|
jasmine.Matchers.prototype.toBeGreaterThan = function(expected) {
|
||||||
|
return this.report(this.actual > expected,
|
||||||
|
'Expected ' + jasmine.Matchers.pp(this.actual) + ' to be greater than ' + jasmine.Matchers.pp(expected) + ', but it was not.');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Matcher that checks that the expected exception was thrown by the actual.
|
* Matcher that checks that the expected exception was thrown by the actual.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user