diff --git a/lib/chai/utils/overwriteMethod.js b/lib/chai/utils/overwriteMethod.js index 1d5f6bd53..438e8b821 100644 --- a/lib/chai/utils/overwriteMethod.js +++ b/lib/chai/utils/overwriteMethod.js @@ -40,7 +40,9 @@ module.exports = function (ctx, name, method) { var _method = ctx[name] - , _super = function () { return this; }; + , _super = function () { + throw new Error(name + ' is not a function'); + }; if (_method && 'function' === typeof _method) _super = _method; diff --git a/test/utilities.js b/test/utilities.js index 4cdb86cd7..2d07c21fd 100644 --- a/test/utilities.js +++ b/test/utilities.js @@ -259,13 +259,30 @@ describe('utilities', function () { expect(_super).to.be.a('function'); return function () { _.flag(this, 'doesnt', true); - _super.apply(this, arguments); } }); }); var dne = expect('something').to.doesnotexist(); expect(dne.__flags).to.have.property('doesnt'); + + chai.use(function (_chai, _) { + expect(_chai.Assertion).to.not.respondTo('doesnotexistfail'); + _chai.Assertion.overwriteMethod('doesnotexistfail', function (_super) { + expect(_super).to.be.a('function'); + return function () { + _.flag(this, 'doesnt', true); + _super.apply(this, arguments); + } + }); + }); + + var dneFail = expect('something'); + var dneError; + try { dneFail.to.doesnotexistfail(); } + catch (e) { dneError = e; } + expect(dneFail.__flags).to.have.property('doesnt'); + expect(dneError.message).to.eql('doesnotexistfail is not a function'); }); it('overwriteMethod returning result', function () {