Skip to content

Commit

Permalink
Merge pull request #701 from vieiralucas/does
Browse files Browse the repository at this point in the history
Add .does as a no-op assertion, Fix #700
  • Loading branch information
lucasfcosta committed May 7, 2016
2 parents df4a261 + 7429954 commit 8e781c4
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/chai/core/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module.exports = function (chai, _) {
* - of
* - same
* - but
* - does
*
* @name language chains
* @namespace BDD
Expand All @@ -43,7 +44,7 @@ module.exports = function (chai, _) {
[ 'to', 'be', 'been'
, 'is', 'and', 'has', 'have'
, 'with', 'that', 'which', 'at'
, 'of', 'same', 'but' ].forEach(function (chain) {
, 'of', 'same', 'but', 'does' ].forEach(function (chain) {
Assertion.addProperty(chain);
});

Expand Down
24 changes: 24 additions & 0 deletions test/expect.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,30 @@ describe('expect', function () {
expect('foo').to.equal('foo');
});

it('no-op chains', function() {
function test(chain) {
// tests that chain exists
expect(expect(1)[chain]).not.undefined;

// tests methods
expect(1)[chain].equal(1);

// tests properties that assert
expect(false)[chain].false;

// tests not
expect(false)[chain].not.true;

// tests chainable methods
expect([1, 2, 3])[chain].contains(1);
}

[ 'to', 'be', 'been'
, 'is', 'and', 'has', 'have'
, 'with', 'that', 'which', 'at'
, 'of', 'same', 'but', 'does' ].forEach(test);
});

it('fail', function () {
err(function() {
expect.fail(0, 1, 'this has failed');
Expand Down
24 changes: 24 additions & 0 deletions test/should.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,30 @@ describe('should', function() {
should.not.equal('foo', 'bar');
});

it('no-op chains', function() {
function test(chain) {
// tests that chain exists
((1).should[chain]).should.not.undefined;

// tests methods
(1).should[chain].equal(1);

// tests properties that assert
(false).should[chain].false;

// tests not
(false).should[chain].not.true;

// tests chainable methods
[1, 2, 3].should[chain].contains(1);
}

[ 'to', 'be', 'been'
, 'is', 'and', 'has', 'have'
, 'with', 'that', 'which', 'at'
, 'of', 'same', 'but', 'does' ].forEach(test);
});

it('fail', function () {
err(function() {
should.fail(0, 1, 'this has failed');
Expand Down

0 comments on commit 8e781c4

Please sign in to comment.