diff --git a/lib/chai/utils/proxify.js b/lib/chai/utils/proxify.js index bd817b34b..3d29d60f4 100644 --- a/lib/chai/utils/proxify.js +++ b/lib/chai/utils/proxify.js @@ -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]; diff --git a/test/expect.js b/test/expect.js index b1e5202c5..6561096df 100644 --- a/test/expect.js +++ b/test/expect.js @@ -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() { diff --git a/test/should.js b/test/should.js index 10536061a..f71300cd5 100644 --- a/test/should.js +++ b/test/should.js @@ -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() { diff --git a/test/utilities.js b/test/utilities.js index 30f7609a7..e4a181243 100644 --- a/test/utilities.js +++ b/test/utilities.js @@ -869,5 +869,14 @@ describe('utilities', function () { pizza.mushrooms; }).to.throw('Invalid Chai property: mushrooms'); }); + + // "then" is whitelisted 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(); + }); }); });