Object asserter.
Assert that the actual value is an object (using .isObject() assertion).
The object() asserter provides adapted assertions for works on an object.
See also the spec of "object" asserter for more examples.
Example
test.object(actual);
Methods
-
is(expected)
-
Assert
actualobject 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
test.object({fluent: 'is awesome', deep: [0, 1]}) .is({fluent: 'is awesome', deep: [0, 1]});
See also -
isNot(expected)
-
Assert
actualobject 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
test.object({fluent: 'is awesome', deep: [0, 1]}) .isNot({fluent: 'is awesome', deep: [0, '1']});
See also -
isIdenticalTo(expected)
-
Assert that the
actualobject is identical to (===)expectedvalue.ParametersName Type Description expected mixedExpected value
ExampleReturnsType Description ObjectThe current instance
var obj = {}, obj2 = obj ; test.object(obj).isIdenticalTo(obj2);
See also -
isNotIdenticalTo(expected)
-
Assert that the
actualobject is not identical to (!==)expectedvalue.ParametersName Type Description expected mixedExpected value
ExampleReturnsType Description ObjectThe current instance
var obj = {}; test.object(obj).isNotIdenticalTo({});
See also -
isEqualTo(expected)
-
Assert that the
actualobject is equal to (==) theexpectedvalue.ParametersName Type Description expected mixedExpected value
ExampleReturnsType Description ObjectThe current instance
var obj = {}, obj2 = obj ; test.object(obj).isEqualTo(obj2);
See also -
isNotEqualTo(expected)
-
Assert that the
actualobject is not equal to (!=) theexpectedvalue.ParametersName Type Description expected mixedExpected value
ExampleReturnsType Description ObjectThe current instance
var obj = {foo: 'bar'}; test.object(obj).isNotEqualTo({foo: 'bar', baz: 'bar'});
See also -
match(expected)
-
Assert
actualobject to match theexpectedvalue.ParametersName Type Description expected StringNumberRegExpfunctionExpected matches
ExampleReturnsType Description ObjectThe current instance
test.object({hello: 'world'}).match(function(obj){ return obj.hello == 'world'; });
See also -
notMatch(expected)
-
Assert
actualobject to not match theexpectedvalue.ParametersName Type Description expected StringNumberRegExpfunctionExpected value that must not match
ExampleReturnsType Description ObjectThe current instance
test.object({hello: 'world'}).notMatch(function(obj){ return obj.hello == 'E.T'; });
See also -
isValid(expected)
-
Alias of
match().ParametersName Type Description expected StringNumberRegExpfunctionExpected matches
ExampleReturnsType Description ObjectThe current instance
test.object({hello: 'world'}).isValid(function(obj){ return obj.hello == 'world'; });
See also -
isNotValid(expected)
-
Alias of
notMatch().ParametersName Type Description expected StringNumberRegExpfunctionExpected matches
ExampleReturnsType Description ObjectThe current instance
test.object({hello: 'world'}).isNotValid(function(obj){ return obj.hello == 'E.T'; });
See also -
matchEach(expected)
-
Assert
actualobject to match eachexpectedvalue.ParametersName Type Description expected ArrayStringNumberRegExpfunctionExpected matches for each
ExampleReturnsType Description ObjectThe current instance
test .object({foo: 'bar', hey: 'you', joker:1}) .matchEach(function(it, key) { if(key == 'joker'){ return (typeof it == 'number'); } return (typeof it == 'string'); }) .exception(function(){ // error if one or several does not match test.object({foo: 'bar', hey: 'you', joker:1}).matchEach(function(it, key) { return (typeof it == 'string'); }); }) ;
See also -
notMatchEach(expected)
-
Assert
actualobject to not match one or severalexpectedvalue.ParametersName Type Description expected ArrayStringNumberRegExpfunctionExpected value that must not match
ExampleReturnsType Description ObjectThe current instance
test .object({foo: 'bar', hey: 'you', joker:1}).notMatchEach(function(it, key) { if(key == 'other'){ return true; } }) .exception(function(){ // error if one or several does not match test.object({foo: 'bar', hey: 'you', joker:1}).notMatchEach(function(it, key) { if(key == 'foo'){ return true; } }); }) .exception(function(){ // error if one or several does not match test.object({foo: 'bar', hey: 'you', joker:1}).notMatchEach(function(it, key) { return (typeof it == 'string'); }); }) ;
See also -
isArray()
-
Assert that
actualobject is anarray(using typeof operator).ExampleReturnsType Description ObjectThe current instance
test.object([]).isArray();
See also -
isRegExp()
-
Assert that the
actualobject is an instance ofRegExp.ExampleReturnsType Description ObjectThe current instance
test .object(/[0-9]+/) .isRegExp() .object(new RegExp('ab+c', 'i')) .isRegExp() ;
See also -
isNotRegExp()
-
Assert that the
actualobject is not an instance ofRegExp.ExampleReturnsType Description ObjectThe current instance
test.object(new Date()).isNotRegExp();
See also -
isDate()
-
Assert that the
actualobject is an instance ofDate.ExampleReturnsType Description ObjectThe current instance
test.object(new Date()).isDate();
See also -
isNotDate()
-
Assert that the
actualobject is not an instance ofDate.ExampleReturnsType Description ObjectThe current instance
test.object(/[0-9]+/).isNotDate();
See also -
isArguments()
-
Assert that the
actualobject is theargumentsobject provided in a function.ExampleReturnsType Description ObjectThe current instance
var fn = function(){ var args = arguments; test.object(arguments).isArguments(); test.object(args).isArguments(); }; fn(1, 2, 3);
See also -
isNotArguments()
-
Assert that the
actualobject is not theargumentsobject provided in a function.ExampleReturnsType Description ObjectThe current instance
var fn = function(){ test .object(arguments) .isArguments() .object([1, 2, 3]) .isNotArguments() .object({0:1, 1:2, 2:3}) .isNotArguments() ; }; fn(1, 2, 3);
See also -
isEmpty()
-
Assert that the
actualobject is empty.Checks either the
lengthfor arrays or the count of enumerable keys. Inherited keys also counted.ExampleReturnsType Description ObjectThe current instance
test.object({}).isEmpty();
See also -
isNotEmpty()
-
Assert that the
actualobject is not empty.Checks either the
lengthfor arrays or the count of enumerable keys. Inherited keys also counted.ExampleReturnsType Description ObjectThe current instance
test.object({hello: 'Nico'}).isNotEmpty();
See also -
hasLength(expected)
-
Assert that the
actualobject has a length property equal toexpectednumber.ParametersName Type Description expected numberExpected length
ExampleReturnsType Description ObjectThe current instance
test.object({foo: 'bar', other: 'baz'}).hasLength(2);
See also -
hasNotLength(expected)
-
Assert that the
actualobject has not a length property equal toexpectednumber.ParametersName Type Description expected numberExpected length
ExampleReturnsType Description ObjectThe current instance
test.object({foo: 'bar', other: 'baz'}).hasNotLength(4);
See also -
isEnumerable(property)
-
Assert that the
actualobject 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
test.object({prop: 'foobar'}).isEnumerable('prop');
See also -
isNotEnumerable(property)
-
Assert that the
actualobject 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 .object(Object.create({}, {prop: {enumerable: 0}})) .isNotEnumerable('prop') ;
See also -
isFrozen()
-
Assert that the
actualobject is frozen withObject.isFrozen.ExampleReturnsType Description ObjectThe current instance
test.object(Object.freeze({})).isFrozen();
See also -
isNotFrozen()
-
Assert that the
actualobject is not frozen withObject.isFrozen.ExampleReturnsType Description ObjectThe current instance
test.object({}).isNotFrozen();
See also -
isInstanceOf(expected)
-
Assert that the
actualobject is an instance ofexpectedvalue.Uses
actual instanceof expected.ParametersName Type Description expected ObjectExpected instance
ExampleReturnsType Description ObjectThe current instance
test.object(new Date()).isInstanceOf(Date);
See also -
isNotInstanceOf(expected)
-
Assert that the
actualobject is not an instance ofexpectedvalue.Uses
actual instanceof expected === false.ParametersName Type Description expected ObjectExpected instance
ExampleReturnsType Description ObjectThe current instance
test.object(new Date()).isNotInstanceOf(RegExp);
See also -
hasProperty(property, value)
-
Assert that the
actualtested object 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 .object({foo: 'bar'}) .hasProperty('foo') .object({foo: 'bar'}) .hasProperty('foo', 'bar') ;
See also -
hasNotProperty(property, value)
-
Assert that the
actualtested object 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 .object({foo: 'bar'}) .hasNotProperty('bar') .object({foo: 'bar'}) .hasNotProperty('foo', 'baz') ;
See also -
hasOwnProperty(property, value)
-
Assert that the
actualtested object 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 .object({foo: 'bar'}) .hasOwnProperty('foo') .object({foo: 'bar'}) .hasOwnProperty('foo', 'bar') ;
See also -
hasNotOwnProperty(property, value)
-
Assert that the
actualtested object 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 .object({foo: 'bar'}) .hasNotOwnProperty('bar') .object({foo: 'bar'}) .hasNotOwnProperty('foo', 'baz') ;
See also -
hasProperties(properties)
-
Assert that the
actualobject has only the expected enumerableproperties. Pass an array of strings asproperties.Takes inherited properties into account. To not do so, see
hasOwnProperties().ParametersName Type Description properties ArrayAn array of expected properties
ExampleReturnsType Description ObjectThe current instance
test.object({foo: 'bar', bar: 'huhu', other: 'vroom'}) .hasProperties(['other', 'bar', 'foo']);
See also -
hasNotProperties(properties)
-
Assert that the
actualobject has not the enumerableproperties. Pass an array of strings asproperties.Takes inherited properties into account. To not do so, see
hasNotOwnProperties().ParametersName Type Description properties ArrayAn array of properties
ExampleReturnsType Description ObjectThe current instance
test.object({foo: 'bar', bar: 'huhu', other: 'vroom'}) .hasNotProperties(['other', 'foo']);
See also -
hasOwnProperties(properties)
-
Assert that the
actualobject has only the expected enumerablepropertiesof its own. Pass an array of strings asproperties.Does not take inherited properties into account. To do so, see
hasProperties.ParametersName Type Description properties ArrayAn array of expected properties
ExampleReturnsType Description ObjectThe current instance
test.object({foo: 'bar', bar: 'huhu', other: 'vroom'}) .hasOwnProperties(['other', 'bar', 'foo']);
See also -
hasKey(key, value)
-
Alias of hasProperty()Assert that the
actualtested object 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 .object({foo: 'bar'}) .hasKey('foo') .object({foo: 'bar'}) .hasKey('foo', 'bar') ;
See also -
notHasKey(key, value)
-
Alias of hasNotProperty()Assert that the
actualtested object 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 .object({foo: 'bar'}) .notHasKey('bar') .object({foo: 'bar'}) .notHasKey('foo', 'baz') ;
See also -
hasKeys(keys)
-
Alias of hasProperties()Assert that the
actualobject has only the expected enumerablekeys. Pass an array of strings askeys.Takes inherited properties into account. To not do so, see
hasOwnProperties().ParametersName Type Description keys ArrayAn array of expected keys
ExampleReturnsType Description ObjectThe current instance
test.object({foo: 'bar', bar: 'huhu', other: 'vroom'}) .hasKeys(['other', 'bar', 'foo']);
See also -
notHasKeys(keys)
-
Alias of hasNotProperties()Assert that the
actualobject has not the enumerablekeys. Pass an array of strings askeys.Takes inherited properties into account. To not do so, see
hasNotOwnProperties().ParametersName Type Description keys ArrayAn array of keys
ExampleReturnsType Description ObjectThe current instance
test.object({foo: 'bar', bar: 'huhu', other: 'vroom'}) .notHasKeys(['other', 'foo']);
See also -
hasValue(expected)
-
Assert that the
actualtested object hasexpectedvalue.For strings it checks the text, for arrays it checks elements and for objects the property values. Everything is checked with strict equals
(===).ParametersName Type Description expected mixedThe expected value
ExampleReturnsType Description ObjectThe current instance
test.object({life: 42, love: 69}).hasValue(42);
See also -
notHasValue(expected)
-
Assert that the
actualtested object not hasexpectedvalue.For strings it checks the text, for arrays it checks elements and for objects the property values. Everything is checked with strict equals
(!==).ParametersName Type Description expected mixedThe expected value
ExampleReturnsType Description ObjectThe current instance
test.object({life: 42, love: 69}).notHasValue(4);
See also -
hasValues(expected)
-
Assert that the
actualtested object has severalexpectedvalues passed in an array of expected values.ParametersName Type Description expected ArrayAn array of expected values
ExampleReturnsType Description ObjectThe current instance
test.object({life: 42, love: 69}).hasValues([42, 69]);
See also -
notHasValues(expected)
-
Assert that the
actualtested object not has severalexpectedvalues passed in an array of expected values.ParametersName Type Description expected ArrayAn array of expected values
ExampleReturnsType Description ObjectThe current instance
test.object({life: 42, love: 69}).notHasValues([43, 68]);
See also -
contains(expected)
-
Assert that the
actualobject to contain something(===)toexpectedwithin depth.ParametersName Type Description expected Array[, other_excepted_values] The expected value
ExampleReturnsType Description ObjectThe current instance
test .object({ a: { b: 10 }, b: { c: 10, d: 11, a: { b: 10, c: 11} }}) .contains({ a: { b: 10 }, b: { c: 10, a: { c: 11 }}}) .object({a: 'a', b: {c: 'c'}}) .contains({b: {c: 'c'}}) .contains({b: {c: 'c'}}, {a: 'a'}) ;
See also -
notContains(expected)
-
Assert that the
actualobject to not contain something(!==)toexpectedwithin depth.ParametersName Type Description expected Array[, other_excepted_values] The expected value
ExampleReturnsType Description ObjectThe current instance
test.object({a: 'a'}, {b: 'b', c: 'c'}).notContains({c: 'b'});
See also -
hasName(expected)
-
Assert that the
actualobject has anexpectedname.ParametersName Type Description expected StringExpected name
ExampleReturnsType Description ObjectThe current instance
test.object(new Date(2010, 5, 28)).hasName('Date');

