Function asserter.
Assert that the actual value is a function (using .isFunction() assertion).
The function() asserter provides adapted assertions for works on a function.
See also the spec of "function" asserter for more examples.
Example
test.function(actual);
Methods
-
is(expected)
-
Assert
actualfunction equality by content and if possible, recursively.Also handles circular and self-referential objects.
For most parts it asserts strict equality (
===), but:- Instances of the same class with a
valueOffunction are compared by its output. - Plain objects and instances of the same class are compared recursively.
Does not coerce types so mismatching types fail. Inherited enumerable properties are also taken into account.
ParametersName Type Description expected mixedExpected value
ExampleReturnsType Description ObjectThe current instance
var fn = function(){}; var ref = fn; test.function(ref).is(fn);
See also - Instances of the same class with a
-
isNot(expected)
-
Assert
actualfunction to the negative equality by content and if possible, recursively.Also handles circular and self-referential objects.
For most parts it asserts strict (
!==), but:- Instances of the same class with a
valueOffunction are compared by its output. - Plain objects and instances of the same class are compared recursively.
Does not coerce types so mismatching types fail. Inherited enumerable properties are also taken into account.
ParametersName Type Description expected mixedExpected value
ExampleReturnsType Description ObjectThe current instance
var fn = function(){}; var otherFunction = function(){}; test.function(fn).isNot(otherFunction);
See also - Instances of the same class with a
-
isIdenticalTo(expected)
-
Assert that the
actualfunction is identical to (===)expectedfunction.ParametersName Type Description expected mixedExpected value
ExampleReturnsType Description ObjectThe current instance
var fn = function(){}; var ref = fn; test.function(ref).isIdenticalTo(fn);
See also -
isNotIdenticalTo(expected)
-
Assert that the
actualfunction is not identical to (!==)expectedfunction.ParametersName Type Description expected mixedExpected value
ExampleReturnsType Description ObjectThe current instance
var fn = function(){}; var otherFunction = function(){}; test.function(fn).isNotIdenticalTo(otherFunction);
See also -
isEqualTo(expected)
-
Assert that the
actualfunction is equal to (==) theexpectedfunction.ParametersName Type Description expected mixedExpected value
ExampleReturnsType Description ObjectThe current instance
var fn = function(){}; var ref = fn; test.function(ref).isEqualTo(fn);
See also -
isNotEqualTo(expected)
-
Assert that the
actualfunction is not equal to (!=) theexpectedfunction.ParametersName Type Description expected mixedExpected value
ExampleReturnsType Description ObjectThe current instance
var fn = function(){}; var otherFunction = function(){}; test.function(fn).isNotEqualTo(otherFunction);
See also -
match(expected)
-
Assert
actualfunction to match theexpectedfunction.ParametersName Type Description expected StringNumberRegExpfunctionExpected matches
ExampleReturnsType Description ObjectThe current instance
var fn = function(){ return 'hello'; }; test.function(fn).match(function(it){ return it() === 'hello'; });
See also -
notMatch(expected)
-
Assert
actualfunction to not match theexpectedfunction.ParametersName Type Description expected StringNumberRegExpfunctionExpected value that must not match
ExampleReturnsType Description ObjectThe current instance
var fn = function(){ return 'hello'; }; test.function(fn).notMatch(function(it){ return it() === 'bye'; });
See also -
isValid(expected)
-
Alias of
match().ParametersName Type Description expected StringNumberRegExpfunctionExpected matches
ExampleReturnsType Description ObjectThe current instance
var fn = function(){ return 'hello'; }; test.function(fn).isValid(function(it){ return it() === 'hello'; });
See also -
isNotValid(expected)
-
Alias of
notMatch().ParametersName Type Description expected StringNumberRegExpfunctionExpected matches
ExampleReturnsType Description ObjectThe current instance
var fn = function(){ return 'hello'; }; test.function(fn).isNotValid(function(it){ return it() === 'bye'; });
See also -
throws(constructor, expected)
-
Assert that the
actualfunction (trigger function) throws.Optionally assert it throws expected (of possibly instance
constructor).Given expected, the error is asserted as follows:
- A string is compared with the exception's
messageproperty. - A regular expression is matched against the exception's
messageproperty. - A function (a.k.a. constructor) is used to check if the error is an
instanceofthat constructor. - All other cases of
expectedare left unspecified for now.
Because of how JavaScript works, the function will be called in
nullcontext (this). If you want to test an instance method, bind it:test.function(obj.method.bind(obj)).throws().ParametersName Type Argument Description constructor StringRegExpfunctionconstructoroptional expected optional ExampleReturnsType Description ObjectThe current instance
// trigger var trigger = function(){ throw new Error("I'm a ninja !") }; test.function(trigger) .throws() .throws("I'm a ninja !") .throws(/ninja/) .throws(Error) .throws(Error, "I'm a ninja !") .throws(Error, /ninja/) .throws(function(err) { if ((err instanceof Error) && /ninja/.test(err) ) { return true; } });
See also - A string is compared with the exception's
-
isError()
-
Assert that the
actualfunction (trigger function) throws an instance ofError(or inherited).ExampleReturnsType Description ObjectThe current instance
// trigger var trigger = function(){ throw new Error("I'm a ninja !") }; test.function(trigger).isError();
See also -
hasName(expected)
-
Assert that the
actualfunction has anexpectedname.ParametersName Type Description expected StringExpected name
ExampleReturnsType Description ObjectThe current instance
test.function(Date).hasName('Date');

