Array asserter.
Assert that the type of actual value is an array (using .isArray() assertion).
The array() asserter provides adapted assertions for works on an array.
See also the spec of "array" asserter for more examples.
Example
test.array(actual);
Methods
-
is(expected)
-
Assert
actualvalue 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.array(['foo', [0, 1]]) .is(['foo', [0, 1]]);
See also -
isNot(expected)
-
Assert
actualvalue 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.array(['foo', [0, 1]]) .isNot(['foo', [0, '1']]);
See also -
isIdenticalTo(expected)
-
Assert that the
actualvalue is identical to (===)expectedvalue.ParametersName Type Description expected mixedExpected value
ExampleReturnsType Description ObjectThe current instance
var arr = [1], arr2 = arr ; test.array(arr).isIdenticalTo(arr2);
See also -
isNotIdenticalTo(expected)
-
Assert that the
actualvalue is not identical to (!==)expectedvalue.ParametersName Type Description expected mixedExpected value
ExampleReturnsType Description ObjectThe current instance
var arr = [1]; test.array(arr).isNotIdenticalTo([1]);
See also -
isEqualTo(expected)
-
Assert that the
actualvalue is equal to (==) theexpectedvalue.ParametersName Type Description expected mixedExpected value
ExampleReturnsType Description ObjectThe current instance
var arr = [1], arr2 = arr ; test.array(arr).isEqualTo(arr2);
See also -
isNotEqualTo(expected)
-
Assert that the
actualvalue is not equal to (!=) theexpectedvalue.ParametersName Type Description expected mixedExpected value
ExampleReturnsType Description ObjectThe current instance
test.array([1]).isNotEqualTo([1]);
See also -
match(expected)
-
Assert
actualvalue to match theexpectedvalue.ParametersName Type Description expected StringNumberRegExpfunctionExpected matches
ExampleReturnsType Description ObjectThe current instance
test // Assert an array with a RegExp .array(['a', 'b', 'c']) .match(/[a-z]/) // Assert an array with a function .array([42, 10]) .match(function(actual) { return actual[1] === 10; }) ;
See also -
notMatch(expected)
-
Assert
actualvalue to not match theexpectedvalue.ParametersName Type Description expected StringNumberRegExpfunctionExpected value that must not match
ExampleReturnsType Description ObjectThe current instance
test.array(['a', 'b', 'c']) .notMatch(/[d-z]/);
See also -
isValid(expected)
-
Alias of
match().ParametersName Type Description expected StringNumberRegExpfunctionExpected matches
ExampleReturnsType Description ObjectThe current instance
test // Assert an array with a RegExp .array(['a', 'b', 'c']) .isValid(/[a-z]/) // Assert an array with a function .array([42, 10]) .isValid(function(actual) { return actual[1] === 10; }) ;
See also -
isNotValid(expected)
-
Alias of
notMatch().ParametersName Type Description expected StringNumberRegExpfunctionExpected matches
ExampleReturnsType Description ObjectThe current instance
test.array(['a', 'b', 'c']) .isNotValid(/[d-z]/);
See also -
matchEach(expected)
-
Assert
actualarray to match eachexpectedvalue.ParametersName Type Description expected ArrayStringNumberRegExpfunctionExpected matches for each
ExampleReturnsType Description ObjectThe current instance
test .array([10, 11, 12]) .matchEach(function(it) { return it >= 10; }) .exception(function(){ // error if one or several does not match test.array([10, 11, 12]) .matchEach(function(it) { return it >= 11; }) }) ;
See also -
notMatchEach(expected)
-
Assert
actualarray to not match one or severalexpectedvalue.ParametersName Type Description expected ArrayStringNumberRegExpfunctionExpected value that must not match
ExampleReturnsType Description ObjectThe current instance
test .array([10, 11, 12]) .notMatchEach(function(it) { return it >= 13; }) .exception(function(){ // error if one or several match test.array([10, 11, 12]) .notMatchEach(function(it) { return it >= 11; }) }) ;
See also -
isEmpty()
-
Assert that the
actualarray is empty. Inherited keys also counted.ExampleReturnsType Description ObjectThe current instance
test.array([]).isEmpty();
See also -
isNotEmpty()
-
Assert that the
actualarray is not empty. Inherited keys also counted.ExampleReturnsType Description ObjectThe current instance
test.array(['hey']).isNotEmpty();
See also -
hasLength(expected)
-
Assert that the
actualarray has a length property equal toexpectednumber.ParametersName Type Description expected numberExpected length
ExampleReturnsType Description ObjectThe current instance
test.array([1, 2]).hasLength(2);
See also -
hasNotLength(expected)
-
Assert that the
actualarray has not a length property equal toexpectednumber.ParametersName Type Description expected numberExpected length
ExampleReturnsType Description ObjectThe current instance
test.array([1, 2]).hasNotLength(1);
See also -
isEnumerable(property)
-
Assert that the
actualarray has an enumerableproperty.ParametersName Type Description property StringThe property name
ExampleReturnsType Description ObjectThe current instance
var arr = ['is enumerable']; test .array(arr) .isEnumerable(0) .array(arr) .isNotEnumerable('length') ;
See also -
isNotEnumerable(property)
-
Assert that the
actualvalue has a non-enumerableproperty.It's the inverse of
isEnumerable().ParametersName Type Description property StringThe property name
ExampleReturnsType Description ObjectThe current instance
var arr = ['is enumerable']; test .array(arr) .isNotEnumerable('length') .array(arr) .isEnumerable(0) ;
See also -
hasProperty(property, value)
-
Assert that the
actualtested array hasproperty. Optionally assert it equals(===)tovalueargument.ParametersName Type Argument Description property StringThe property name
value mixedoptional The property value
ExampleReturnsType Description ObjectThe current instance
test .array(['a', 'b']) .hasProperty(1) .hasProperty(0, 'a') ;
See also -
hasNotProperty(property, value)
-
Assert that the
actualtested array has not aproperty. Optionally assert it not equals(!==)tovalueargument.ParametersName Type Argument Description property StringThe property name
value mixedoptional The property value
ExampleReturnsType Description ObjectThe current instance
test .array(['a', 'b']) .hasNotProperty(2) .hasNotProperty(0, 'b') ;
See also -
hasKey(key, value)
-
Alias of hasProperty()Assert that the
actualtested array has akey. Optionally assert it equals(===)tovalueargument.ParametersName Type Argument Description key StringThe key name
value mixedoptional The key value
ExampleReturnsType Description ObjectThe current instance
test .array(['a', 'b']) .hasKey(1) .hasKey(0, 'a') ;
See also -
notHasKey(key, value)
-
Alias of hasNotProperty()Assert that the
actualtested array has not akey. Optionally assert it not equals(!==)tovalueargument.ParametersName Type Argument Description key StringThe key name
value mixedoptional The key value
ExampleReturnsType Description ObjectThe current instance
test .array(['a', 'b']) .notHasKey(2) .notHasKey(0, 'b') ;
See also -
hasValue(expected)
-
Assert that the
actualtested array hasexpectedvalue.ParametersName Type Description expected mixedThe expected value
ExampleReturnsType Description ObjectThe current instance
test .array([1, 42, 3]) .hasValue(42) ;
See also -
notHasValue(expected)
-
Assert that the
actualtested array not hasexpectedvalue.ParametersName Type Description expected mixedThe expected value
ExampleReturnsType Description ObjectThe current instance
test .array([1, 42, 3]) .notHasValue(4) ;
See also -
hasValues(expected)
-
Assert that the
actualtested array has severalexpectedvalues passed in an array of expected values.ParametersName Type Description expected ArrayAn array of expected values
ExampleReturnsType Description ObjectThe current instance
test .array([1, 42, 3]) .hasValues([42, 3]) ;
See also -
notHasValues(expected)
-
Assert that the
actualtested array 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 .array([1, 42, 3]) .notHasValues([4, 2]) ;
See also -
contains(expected)
-
Assert that the
actualarray to contain something(===)toexpectedwithin depth.ParametersName Type Description expected Array[, other_excepted_values] The expected value
ExampleReturnsType Description ObjectThe current instance
test .array([1,2,3]) .contains([3]) .array([1,2,3]) .contains([1, 3]) .array([1,2,3]) .contains([3], [1, 3]) .array([1, 2, 3, { a: { b: { d: 12 }}}]) .contains([2], [1, 2], [{ a: { b: {d: 12}}}]) .array([[1],[2],[3]]) .contains([[3]]) .array([[1],[2],[3, 4]]) .contains([[3]]) .array([{a: 'a'}, {b: 'b', c: 'c'}]) .contains([{a: 'a'}], [{b: 'b'}]) ;
See also -
notContains(expected)
-
Assert that the
actualarray to not contain something(!==)toexpectedwithin depth.ParametersName Type Description expected Array[, other_excepted_values] The expected value
ExampleReturnsType Description ObjectThe current instance
test .array([[1],[2],[3, 4]]) .notContains([[0]]) .array([{a: 'a'}, {b: 'b', c: 'c'}]) .notContains([{a: 'b'}], [{c: 'b'}]) ;
See also -
isReverseOf(expected)
-
Assert that the
actualtested array is the reverse to theexpectedarray. An array is a reverse of another if they both have the same elements (including the same number of duplicates) regardless of their order. Elements are checked with strict equals (===).ParametersName Type Description expected ArrayThe expected reverse array.
ExampleReturnsType Description ObjectThe current instance
test .array([1, 2, 3]) .isReverseOf([3, 2, 1]) ;
See also -
isNotReverseOf(expected)
-
Assert that the
actualtested array is not the reverse to theexpectedarray. An array is a reverse of another if they both have the same elements (including the same number of duplicates) regardless of their order. Elements are checked with strict equals (===).ParametersName Type Description expected ArrayThe expected reverse array.
ExampleReturnsType Description ObjectThe current instance
test .array([1, 2, 3]) .isNotReverseOf([1, 2, 3]) ;
See also

