Exception asserter.
Assert that the actual value is an exception
and is an instance of Error (or inherited).
The error() asserter provides adapted assertions for works on an Error exception.
See also the spec of "error" asserter for more examples.
Example
var trigger = function(){
throw new Error('Whoops !');
};
test.error(trigger);
Methods
-
is(expected)
-
Assert
actualErrorexception equality by content and if possible, recursively.Also handles circular and self-referential objects.
For most parts it asserts strict equality (
===), but:Booleanobjects are compared to boolean literals.Numberobjects are compared to number literals.Stringobjects are compared to string literals.RegExpobjects are compared by their pattern and flags.Dateobjects are compared by their value.Arrayobjects are compared recursively.NaNs are considered equivalent.- 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 error = new Error('Whoops !'); var trigger = function(){ throw error; }; test .error(trigger) .is(error) .is(new Error('Whoops !')) ;
See also -
isNot(expected)
-
Assert
actualErrorexception to the negative equality by content and if possible, recursively.Also handles circular and self-referential objects.
For most parts it asserts strict (
!==), but:Booleanobjects are compared to boolean literals.Numberobjects are compared to number literals.Stringobjects are compared to string literals.RegExpobjects are compared by their pattern and flags.Dateobjects are compared by their value.Arrayobjects are compared recursively.NaNs are considered equivalent.- 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 error = new Error('Whoops !'); var trigger = function(){ throw error; }; test.error(trigger).isNot({message: 'Whoops !'});
See also -
isIdenticalTo(expected)
-
Assert that the
actualErrorexception is identical to (===)expectedvalue.ParametersName Type Description expected mixedExpected value
ExampleReturnsType Description ObjectThe current instance
var error = new Error('Whoops !'); var trigger = function(){ throw error; }; test.error(trigger).isIdenticalTo(error);
See also -
isNotIdenticalTo(expected)
-
Assert that the
actualErrorexception is not identical to (!==)expectedvalue.ParametersName Type Description expected mixedExpected value
ExampleReturnsType Description ObjectThe current instance
var error = new Error('Whoops !'); var trigger = function(){ throw error; }; test.error(trigger).isNotIdenticalTo(new Error('Whoops !'));
See also -
isEqualTo(expected)
-
Assert that the
actualErrorexception is equal to (==) theexpectedvalue.ParametersName Type Description expected mixedExpected value
ExampleReturnsType Description ObjectThe current instance
var error = new Error('Whoops !'); var trigger = function(){ throw error; }; test.error(trigger).isEqualTo(error);
See also -
isNotEqualTo(expected)
-
Assert that the
actualErrorexception is not equal to (!=) theexpectedvalue.ParametersName Type Description expected mixedExpected value
ExampleReturnsType Description ObjectThe current instance
var error = new Error('Whoops !'); var trigger = function(){ throw error; }; test.error(trigger).isNotEqualTo(new Error('Whoops !'));
See also -
match(expected)
-
Assert
actualErrorexception to match theexpectedvalue.ParametersName Type Description expected StringNumberRegExpfunctionExpected matches
ExampleReturnsType Description ObjectThe current instance
test .error(function(){ throw new Error('Whoops!'); }) .match('Whoops!') .match(/Whoops/) .match(function(exception){ return /whoops/i.test(exception); }) ;
See also -
notMatch(expected)
-
Assert
actualErrorexception to not match theexpectedvalue.ParametersName Type Description expected StringNumberRegExpfunctionExpected value that must not match
ExampleReturnsType Description ObjectThe current instance
test .error(function(){ throw new Error('Whoops!'); }) .notMatch('Yeah an error') .notMatch(/Yeah/) .notMatch(function(exception){ return /yeah/.test(exception); }) ;
See also -
isValid(expected)
-
Alias of
match().ParametersName Type Description expected StringNumberRegExpfunctionExpected matches
ExampleReturnsType Description ObjectThe current instance
test .error(function(){ throw new Error('Whoops!'); }) .isValid('Whoops!') .isValid(/Whoops/) .isValid(function(exception){ return /whoops/i.test(exception); }) ;
See also -
isNotValid(expected)
-
Alias of
notMatch().ParametersName Type Description expected StringNumberRegExpfunctionExpected matches
ExampleReturnsType Description ObjectThe current instance
test .error(function(){ throw new Error('Whoops!'); }) .isNotValid('Yeah an error') .isNotValid(/Yeah/) .isNotValid(function(exception){ return /yeah/.test(exception); }) ;
See also -
isEnumerable(property)
-
Assert that the
actualErrorexception has an enumerableproperty. It will fail if theactualvalue lacks thepropertyentirely.This also checks inherited properties in the prototype chain, something which
Object.prototype.propertyIsEnumerableitself does not do.For checking if a property exists and is non-enumerable, see
isNotEnumerable().ParametersName Type Description property StringThe property name
ExampleReturnsType Description ObjectThe current instance
var error = new Error('Whoops !'); error.foo = 'bar'; test .error(function(){ throw error; }) .isEnumerable('foo') ;
See also -
isNotEnumerable(property)
-
Assert that the
actualErrorexception has a non-enumerableproperty. It will fail if theactualvalue lacks thepropertyentirely.This also checks inherited properties in the prototype chain, something which
Object.prototype.propertyIsEnumerableitself does not do.It's the inverse of
isEnumerable().ParametersName Type Description property StringThe property name
ExampleReturnsType Description ObjectThe current instance
test .error(function(){ throw new Error('Whoops !'); }) .isNotEnumerable('message') ;
See also -
isFrozen()
-
Assert that the
actualErrorexception is frozen withObject.isFrozen.ExampleReturnsType Description ObjectThe current instance
var frozenError = new Error('Whoops !'); Object.freeze(frozenError); test .error(function(){ throw frozenError; }) .isFrozen() ;
See also -
isNotFrozen()
-
Assert that the
actualErrorexception is not frozen withObject.isFrozen.ExampleReturnsType Description ObjectThe current instance
test .error(function(){ throw new Error('Whoops !'); }) .isNotFrozen() ;
See also -
isInstanceOf(expected)
-
Assert that the
actualErrorexception is an instance ofexpectedvalue.Uses
actual instanceof expected.ParametersName Type Description expected ObjectExpected instance
ExampleReturnsType Description ObjectThe current instance
test .error(function(){ throw new TypeError('Whoops !'); }) .isInstanceOf(TypeError) ;
See also -
isNotInstanceOf(expected)
-
Assert that the
actualErrorexception is not an instance ofexpectedvalue.Uses
actual instanceof expected === false.ParametersName Type Description expected ObjectExpected instance
ExampleReturnsType Description ObjectThe current instance
test .error(function(){ throw new Error('Whoops !'); }) .isNotInstanceOf(TypeError) ;
See also -
hasProperty(property, value)
-
Assert that the
actualtestedErrorexception hasproperty. Optionally assert it equals(===)tovalueargument.Takes inherited properties into account. To not do so, see
hasOwnProperty().ParametersName Type Argument Description property StringThe property name
value mixedoptional The property value
ExampleReturnsType Description ObjectThe current instance
test .error(function(){ throw new Error('Whoops !'); }) .hasProperty('message') .hasProperty('message', 'Whoops !') .hasProperty('constructor') ;
See also -
hasNotProperty(property, value)
-
Assert that the
actualtestedErrorexception has not aproperty. Optionally assert it not equals(!==)tovalueargument.Takes inherited properties into account. To not do so, see
hasNotOwnProperty().ParametersName Type Argument Description property StringThe property name
value mixedoptional The property value
ExampleReturnsType Description ObjectThe current instance
test .error(function(){ throw new Error('Whoops !'); }) .hasNotProperty('foo') .hasNotProperty('message', 'whoops') ;
See also -
hasOwnProperty(property, value)
-
Assert that the
actualtestedErrorexception has ownproperty. Optionally assert it equals(===)tovalueargument.Does not take inherited properties into account. To do so, see
hasProperty().ParametersName Type Argument Description property StringThe property name
value mixedoptional The property value
ExampleReturnsType Description ObjectThe current instance
test .error(function(){ throw new Error('Whoops !'); }) .hasOwnProperty('message') .hasOwnProperty('message', 'Whoops !') ;
See also -
hasNotOwnProperty(property, value)
-
Assert that the
actualtestedErrorexception has not ownproperty. Optionally assert it not equals(!==)tovalueargument.Does not take inherited properties into account. To do so, see
hasNotProperty().ParametersName Type Argument Description property StringThe property name
value mixedoptional The property value
ExampleReturnsType Description ObjectThe current instance
test .error(function(){ throw new Error('Whoops !'); }) .hasNotOwnProperty('foo') .hasNotOwnProperty('message', 'Grrrr !') .hasNotOwnProperty('constructor') ;
See also -
hasKey(key, value)
-
Alias of hasProperty()Assert that the
actualtestedErrorexception has akey. Optionally assert it equals(===)tovalueargument.Takes inherited properties into account. To not do so, see
hasOwnProperty().ParametersName Type Argument Description key StringThe key name
value mixedoptional The key value
ExampleReturnsType Description ObjectThe current instance
test .error(function(){ throw new Error('Whoops !'); }) .hasKey('message') .hasKey('message', 'Whoops !') .hasKey('constructor') ;
See also -
notHasKey(key, value)
-
Alias of hasNotProperty()Assert that the
actualtestedErrorexception has not akey. Optionally assert it not equals(!==)tovalueargument.Takes inherited properties into account. To not do so, see
hasNotOwnProperty().ParametersName Type Argument Description key StringThe key name
value mixedoptional The key value
ExampleReturnsType Description ObjectThe current instance
test .error(function(){ throw new Error('Whoops !'); }) .notHasKey('foo') .notHasKey('message', 'whoops') ;
See also -
hasMessage(expected)
-
Alias of
match().Assert that the
actualErrorexception has anexpectedmessage.ParametersName Type Description expected StringRegExpExpected message
ExampleReturnsType Description ObjectThe current instance
test .error(function(){ throw new Error('Whoops!'); }) .hasMessage('Whoops!') .hasMessage(/Whoops/) ;
See also

