Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@

0.3.3 / 2014-??-??
==================

* added .lessThanOrEqual() and .greaterThanOrEqual()


0.3.0 / 2014-02-20
==================

Expand Down
32 changes: 32 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,22 @@
return this;
};

/**
* Assert numeric value above or equal _n_.
*
* @param {Number} n
* @api public
*/

Assertion.prototype.greaterThanOrEqual =
Assertion.prototype.aboveOrEqual = function (n) {
this.assert(
this.obj >= n
, function(){ return 'expected ' + i(this.obj) + ' to be above or equal ' + n }
, function(){ return 'expected ' + i(this.obj) + ' to be below ' + n });
return this;
};

/**
* Assert numeric value below _n_.
*
Expand All @@ -317,6 +333,22 @@
return this;
};

/**
* Assert numeric value below or equal _n_.
*
* @param {Number} n
* @api public
*/

Assertion.prototype.lessThanOrEqual =
Assertion.prototype.belowOrEqual = function (n) {
this.assert(
this.obj <= n
, function(){ return 'expected ' + i(this.obj) + ' to be below or equal ' + n }
, function(){ return 'expected ' + i(this.obj) + ' to be above ' + n });
return this;
};

/**
* Assert string value matches _regexp_.
*
Expand Down
2 changes: 1 addition & 1 deletion test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
*/

// expose the globals that are obtained through `<script>` on the browser
expect = require('../expect')
expect = require('../index');
38 changes: 36 additions & 2 deletions test/expect.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,43 @@ describe('expect', function () {
}, "expected 10 to be below 6");
});

it('should test aboveOrEqual(n)', function () {
expect(5).to.be.aboveOrEqual(2);
expect(5).to.be.aboveOrEqual(5);
expect(5).to.be.greaterThanOrEqual(2);
expect(5).to.be.greaterThanOrEqual(5);
expect(5).to.not.be.aboveOrEqual(6);
expect(5).to.not.be.greaterThanOrEqual(6);

err(function () {
expect(5).to.be.aboveOrEqual(6);
}, "expected 5 to be above or equal 6");

err(function () {
expect(10).to.not.be.aboveOrEqual(6);
}, "expected 10 to be below 6");
});

it('should test belowOrEqual(n)', function () {
expect(5).to.be.belowOrEqual(9);
expect(5).to.be.belowOrEqual(5);
expect(5).to.be.lessThanOrEqual(9);
expect(5).to.be.lessThanOrEqual(5);
expect(5).to.not.be.belowOrEqual(3);
expect(5).to.not.be.lessThanOrEqual(3);

err(function () {
expect(5).to.be.belowOrEqual(3);
}, "expected 5 to be below or equal 3");

err(function () {
expect(10).to.not.be.belowOrEqual(30);
}, "expected 10 to be above 30");
});

it('should test match(regexp)', function () {
expect('foobar').to.match(/^foo/)
expect('foobar').to.not.match(/^bar/)
expect('foobar').to.match(/^foo/);
expect('foobar').to.not.match(/^bar/);

err(function () {
expect('foobar').to.match(/^bar/i)
Expand Down