mirror of
https://github.com/chaijs/chai
synced 2024-11-15 00:07:11 +00:00
Add respondsTo and satisfies as aliases
This commit is contained in:
parent
6ee53e438a
commit
802fa5e0bb
1 changed files with 12 additions and 4 deletions
|
@ -1368,12 +1368,13 @@ module.exports = function (chai, _) {
|
||||||
* expect(Klass).itself.to.respondTo('baz');
|
* expect(Klass).itself.to.respondTo('baz');
|
||||||
*
|
*
|
||||||
* @name respondTo
|
* @name respondTo
|
||||||
|
* @alias respondsTo
|
||||||
* @param {String} method
|
* @param {String} method
|
||||||
* @param {String} message _optional_
|
* @param {String} message _optional_
|
||||||
* @api public
|
* @api public
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Assertion.addMethod('respondTo', function (method, msg) {
|
function respondTo (method, msg) {
|
||||||
if (msg) flag(this, 'message', msg);
|
if (msg) flag(this, 'message', msg);
|
||||||
var obj = flag(this, 'object')
|
var obj = flag(this, 'object')
|
||||||
, itself = flag(this, 'itself')
|
, itself = flag(this, 'itself')
|
||||||
|
@ -1386,7 +1387,10 @@ module.exports = function (chai, _) {
|
||||||
, 'expected #{this} to respond to ' + _.inspect(method)
|
, 'expected #{this} to respond to ' + _.inspect(method)
|
||||||
, 'expected #{this} to not respond to ' + _.inspect(method)
|
, 'expected #{this} to not respond to ' + _.inspect(method)
|
||||||
);
|
);
|
||||||
});
|
}
|
||||||
|
|
||||||
|
Assertion.addMethod('respondTo', respondTo);
|
||||||
|
Assertion.addMethod('respondsTo', respondTo);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ### .itself
|
* ### .itself
|
||||||
|
@ -1416,12 +1420,13 @@ module.exports = function (chai, _) {
|
||||||
* expect(1).to.satisfy(function(num) { return num > 0; });
|
* expect(1).to.satisfy(function(num) { return num > 0; });
|
||||||
*
|
*
|
||||||
* @name satisfy
|
* @name satisfy
|
||||||
|
* @alias satisfies
|
||||||
* @param {Function} matcher
|
* @param {Function} matcher
|
||||||
* @param {String} message _optional_
|
* @param {String} message _optional_
|
||||||
* @api public
|
* @api public
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Assertion.addMethod('satisfy', function (matcher, msg) {
|
function satisfy (matcher, msg) {
|
||||||
if (msg) flag(this, 'message', msg);
|
if (msg) flag(this, 'message', msg);
|
||||||
var obj = flag(this, 'object');
|
var obj = flag(this, 'object');
|
||||||
var result = matcher(obj);
|
var result = matcher(obj);
|
||||||
|
@ -1432,7 +1437,10 @@ module.exports = function (chai, _) {
|
||||||
, this.negate ? false : true
|
, this.negate ? false : true
|
||||||
, result
|
, result
|
||||||
);
|
);
|
||||||
});
|
}
|
||||||
|
|
||||||
|
Assertion.addMethod('satisfy', satisfy);
|
||||||
|
Assertion.addMethod('satisfies', satisfy);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ### .closeTo(expected, delta)
|
* ### .closeTo(expected, delta)
|
||||||
|
|
Loading…
Reference in a new issue