From 0c1d28067a4ce2234a3a497460f1363c3ca08f2d Mon Sep 17 00:00:00 2001 From: Grant Snodgrass Date: Fri, 10 Jun 2016 06:18:53 -0400 Subject: [PATCH] Whitelist .then from proxy check --- lib/chai/utils/proxify.js | 7 +++++-- test/expect.js | 5 +++++ test/should.js | 5 +++++ 3 files changed, 15 insertions(+), 2 deletions(-) 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() {