Skip to content

Commit

Permalink
Merge pull request #528 from wbyoung/throw-super-overwrite-method
Browse files Browse the repository at this point in the history
Throw when calling _super on overwriteMethod if method is undefined
  • Loading branch information
keithamus committed Oct 4, 2015
2 parents ac78e36 + 2f4cd16 commit c772b42
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 c772b42

Please sign in to comment.