From f3adfd911ea4bd7c356b3efdc8ab047628dde10a Mon Sep 17 00:00:00 2001 From: Grant Snodgrass Date: Mon, 8 May 2017 16:22:54 -0400 Subject: [PATCH] fix: PhantomJS 1.x incompatibility (#966) --- lib/chai/utils/addChainableMethod.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/chai/utils/addChainableMethod.js b/lib/chai/utils/addChainableMethod.js index 3e1edcbdc..a713f6ac8 100644 --- a/lib/chai/utils/addChainableMethod.js +++ b/lib/chai/utils/addChainableMethod.js @@ -25,7 +25,16 @@ var canSetPrototype = typeof Object.setPrototypeOf === 'function'; // However, some of functions' own props are not configurable and should be skipped. var testFn = function() {}; var excludeNames = Object.getOwnPropertyNames(testFn).filter(function(name) { - return !Object.getOwnPropertyDescriptor(testFn, name).configurable; + var propDesc = Object.getOwnPropertyDescriptor(testFn, name); + + // Note: PhantomJS 1.x includes `callee` as one of `testFn`'s own properties, + // but then returns `undefined` as the property descriptor for `callee`. As a + // workaround, we perform an otherwise unnecessary type-check for `propDesc`, + // and then filter it out if it's not an object as it should be. + if (typeof propDesc !== 'object') + return true; + + return !propDesc.configurable; }); // Cache `Function` properties