diff --git a/lib/chai/utils/addMethod.js b/lib/chai/utils/addMethod.js index 7c97a96b0..439201a5c 100644 --- a/lib/chai/utils/addMethod.js +++ b/lib/chai/utils/addMethod.js @@ -4,7 +4,9 @@ * MIT Licensed */ +var chai = require('../../chai'); var config = require('../config'); +var flag = require('./flag'); var transferFlags = require('./transferFlags'); /** @@ -32,18 +34,19 @@ var transferFlags = require('./transferFlags'); * @name addMethod * @api public */ -var flag = require('./flag'); module.exports = function (ctx, name, method) { ctx[name] = function () { var old_ssfi = flag(this, 'ssfi'); if (old_ssfi && config.includeStack === false) flag(this, 'ssfi', ctx[name]); + var result = method.apply(this, arguments); + if (result !== undefined) + return result; var newAssertion = new chai.Assertion(); transferFlags(this, newAssertion); - - return result === undefined ? newAssertion: result; + return newAssertion; }; }; diff --git a/lib/chai/utils/addProperty.js b/lib/chai/utils/addProperty.js index 64e69ba32..cccb05996 100644 --- a/lib/chai/utils/addProperty.js +++ b/lib/chai/utils/addProperty.js @@ -4,6 +4,7 @@ * MIT Licensed */ +var chai = require('../../chai'); var config = require('../config'); var flag = require('./flag'); var transferFlags = require('./transferFlags'); @@ -44,10 +45,12 @@ module.exports = function (ctx, name, getter) { flag(this, 'ssfi', addProperty); var result = getter.call(this); + if (result !== undefined) + return result; + var newAssertion = new chai.Assertion(); transferFlags(this, newAssertion); - - return result === undefined ? newAssertion: result; + return newAssertion; } , configurable: true });