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

Add respondsTo and satisfies as aliases #484

Merged
merged 1 commit into from
Jul 17, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions lib/chai/core/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1368,12 +1368,13 @@ module.exports = function (chai, _) {
* expect(Klass).itself.to.respondTo('baz');
*
* @name respondTo
* @alias respondsTo
* @param {String} method
* @param {String} message _optional_
* @api public
*/

Assertion.addMethod('respondTo', function (method, msg) {
function respondTo (method, msg) {
if (msg) flag(this, 'message', msg);
var obj = flag(this, 'object')
, itself = flag(this, 'itself')
Expand All @@ -1386,7 +1387,10 @@ module.exports = function (chai, _) {
, 'expected #{this} to respond to ' + _.inspect(method)
, 'expected #{this} to not respond to ' + _.inspect(method)
);
});
}

Assertion.addMethod('respondTo', respondTo);
Assertion.addMethod('respondsTo', respondTo);

/**
* ### .itself
Expand Down Expand Up @@ -1416,12 +1420,13 @@ module.exports = function (chai, _) {
* expect(1).to.satisfy(function(num) { return num > 0; });
*
* @name satisfy
* @alias satisfies
* @param {Function} matcher
* @param {String} message _optional_
* @api public
*/

Assertion.addMethod('satisfy', function (matcher, msg) {
function satisfy (matcher, msg) {
if (msg) flag(this, 'message', msg);
var obj = flag(this, 'object');
var result = matcher(obj);
Expand All @@ -1432,7 +1437,10 @@ module.exports = function (chai, _) {
, this.negate ? false : true
, result
);
});
}

Assertion.addMethod('satisfy', satisfy);
Assertion.addMethod('satisfies', satisfy);

/**
* ### .closeTo(expected, delta)
Expand Down