diff --git a/lib/jasmine.js b/lib/jasmine.js index 785bee46..a1be3be9 100644 --- a/lib/jasmine.js +++ b/lib/jasmine.js @@ -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.'); }; +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. * diff --git a/spec/suites/MatchersTest.js b/spec/suites/MatchersTest.js index 5a3d18e3..5199ae0e 100644 --- a/spec/suites/MatchersTest.js +++ b/spec/suites/MatchersTest.js @@ -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() { var expected = new jasmine.Matchers(env, function() { throw new Error("Fake Error"); diff --git a/src/Matchers.js b/src/Matchers.js index cb078e83..f69b858a 100644 --- a/src/Matchers.js +++ b/src/Matchers.js @@ -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.'); }; +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. *