Skip to content

Commit

Permalink
No longer silently allowing undefined method calls. Fixes chaijs#467.
Browse files Browse the repository at this point in the history
  • Loading branch information
wbyoung committed Oct 4, 2015
1 parent ac78e36 commit 2f4cd16
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/chai/utils/overwriteMethod.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,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;
Expand Down
19 changes: 18 additions & 1 deletion test/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit 2f4cd16

Please sign in to comment.