Skip to content

Commit

Permalink
Whitelist .then from proxy check
Browse files Browse the repository at this point in the history
  • Loading branch information
meeber committed Jun 10, 2016
1 parent ef0f1a8 commit 0c1d280
Show file tree
Hide file tree
Showing 3 changed files with 15 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 support.
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 whitelisted 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 whitelisted from property validation for promise support
(function () {
(42).should.then;
}).should.not.throw();
});

it('no-op chains', function() {
Expand Down

0 comments on commit 0c1d280

Please sign in to comment.