Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw when calling _super on overwriteMethod if method is undefined #528

Merged
merged 1 commit into from
Oct 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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