Skip to content

Commit

Permalink
Exclude .then from property validation
Browse files Browse the repository at this point in the history
  • Loading branch information
meeber committed Jun 10, 2016
1 parent ef0f1a8 commit 9625fe8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/chai/utils/proxify.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ module.exports = function proxify (obj) {

return new Proxy(obj, {
get: function getProperty (target, property) {
// Don't throw error on Symbol properties such as Symbol.toStringTag
if (typeof property === 'string' && !Reflect.has(target, property))
// Don't throw error on Symbol properties such as Symbol.toStringTag, nor
// on .then because it's necessary for promise type-checking.
if (typeof property === 'string' &&
property !== 'then' &&
!Reflect.has(target, property))
throw Error('Invalid Chai property: ' + property);

return target[property];
Expand Down
5 changes: 5 additions & 0 deletions test/expect.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ describe('expect', function () {
err(function () {
expect(42).to.equal(42).pizza;
}, 'Invalid Chai property: pizza');

// .then is excluded from property validation for promise support
expect(function () {
expect(42).then;
}).to.not.throw();
});

it('no-op chains', function() {
Expand Down
5 changes: 5 additions & 0 deletions test/should.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ describe('should', function() {
err(function () {
(42).should.equal(42).pizza;
}, 'Invalid Chai property: pizza');

// .then is excluded from property validation for promise support
(function () {
(42).should.then;
}).should.not.throw();
});

it('no-op chains', function() {
Expand Down
9 changes: 9 additions & 0 deletions test/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -869,5 +869,14 @@ describe('utilities', function () {
pizza.mushrooms;
}).to.throw('Invalid Chai property: mushrooms');
});

// .then is excluded from property validation for promise support
it('doesn\'t throw error if non-existent `then` is read', function () {
var pizza = proxify({});

expect(function () {
pizza.then;
}).to.not.throw();
});
});
});

0 comments on commit 9625fe8

Please sign in to comment.