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
actual
value equality by content and if possible, recursively.Also handles circular and self-referential objects.
For most parts it asserts strict equality (
===
), but:Boolean
objects are compared to boolean literals.Number
objects are compared to number literals.String
objects are compared to string literals.RegExp
objects are compared by their pattern and flags.Date
objects are compared by their value.Array
objects are compared recursively.NaN
s are considered equivalent.- Instances of the same class with a
valueOf
function 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
ReturnsType Description ObjectThe current instance
test.array(['foo', [0, 1]]) .is(['foo', [0, 1]]);
See also -
isNot(expected)
-
Assert
actual
value to the negative equality by content and if possible, recursively.Also handles circular and self-referential objects.
For most parts it asserts strict (
!==
), but:Boolean
objects are compared to boolean literals.Number
objects are compared to number literals.String
objects are compared to string literals.RegExp
objects are compared by their pattern and flags.Date
objects are compared by their value.Array
objects are compared recursively.NaN
s are considered equivalent.- Instances of the same class with a
valueOf
function 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
ReturnsType Description ObjectThe current instance
test.array(['foo', [0, 1]]) .isNot(['foo', [0, '1']]);
See also -
isIdenticalTo(expected)
-
Assert that the
actual
value is identical to (===
)expected
value.ParametersName Type Description expected mixedExpected value
ReturnsType Description ObjectThe current instance
var arr = [1], arr2 = arr ; test.array(arr).isIdenticalTo(arr2);
See also -
isNotIdenticalTo(expected)
-
Assert that the
actual
value is not identical to (!==
)expected
value.ParametersName Type Description expected mixedExpected value
ReturnsType Description ObjectThe current instance
var arr = [1]; test.array(arr).isNotIdenticalTo([1]);
See also -
isEqualTo(expected)
-
Assert that the
actual
value is equal to (==
) theexpected
value.ParametersName Type Description expected mixedExpected value
ReturnsType Description ObjectThe current instance
var arr = [1], arr2 = arr ; test.array(arr).isEqualTo(arr2);
See also -
isNotEqualTo(expected)
-
Assert that the
actual
value is not equal to (!=
) theexpected
value.ParametersName Type Description expected mixedExpected value
ReturnsType Description ObjectThe current instance
test.array([1]).isNotEqualTo([1]);
See also -
match(expected)
-
Assert
actual
value to match theexpected
value.ParametersName Type Description expected StringNumberRegExpfunctionExpected matches
ReturnsType 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
actual
value to not match theexpected
value.ParametersName Type Description expected StringNumberRegExpfunctionExpected value that must not match
ReturnsType 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
ReturnsType 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
ReturnsType Description ObjectThe current instance
test.array(['a', 'b', 'c']) .isNotValid(/[d-z]/);
See also -
matchEach(expected)
-
Assert
actual
array to match eachexpected
value.ParametersName Type Description expected ArrayStringNumberRegExpfunctionExpected matches for each
ReturnsType 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
actual
array to not match one or severalexpected
value.ParametersName Type Description expected ArrayStringNumberRegExpfunctionExpected value that must not match
ReturnsType 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
actual
array is empty. Inherited keys also counted.ReturnsType Description ObjectThe current instance
test.array([]).isEmpty();
See also -
isNotEmpty()
-
Assert that the
actual
array is not empty. Inherited keys also counted.ReturnsType Description ObjectThe current instance
test.array(['hey']).isNotEmpty();
See also -
hasLength(expected)
-
Assert that the
actual
array has a length property equal toexpected
number.ParametersName Type Description expected numberExpected length
ReturnsType Description ObjectThe current instance
test.array([1, 2]).hasLength(2);
See also -
hasNotLength(expected)
-
Assert that the
actual
array has not a length property equal toexpected
number.ParametersName Type Description expected numberExpected length
ReturnsType Description ObjectThe current instance
test.array([1, 2]).hasNotLength(1);
See also -
isEnumerable(property)
-
Assert that the
actual
array has an enumerableproperty
.ParametersName Type Description property StringThe property name
ReturnsType Description ObjectThe current instance
var arr = ['is enumerable']; test .array(arr) .isEnumerable(0) .array(arr) .isNotEnumerable('length') ;
See also -
isNotEnumerable(property)
-
Assert that the
actual
value has a non-enumerableproperty
.It's the inverse of
isEnumerable()
.ParametersName Type Description property StringThe property name
ReturnsType 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
actual
tested array hasproperty
. Optionally assert it equals(===)
tovalue
argument.ParametersName Type Argument Description property StringThe property name
value mixedoptional The property value
ReturnsType Description ObjectThe current instance
test .array(['a', 'b']) .hasProperty(1) .hasProperty(0, 'a') ;
See also -
hasNotProperty(property, value)
-
Assert that the
actual
tested array has not aproperty
. Optionally assert it not equals(!==)
tovalue
argument.ParametersName Type Argument Description property StringThe property name
value mixedoptional The property value
ReturnsType Description ObjectThe current instance
test .array(['a', 'b']) .hasNotProperty(2) .hasNotProperty(0, 'b') ;
See also -
hasKey(key, value)
-
Alias of hasProperty()
Assert that the
actual
tested array has akey
. Optionally assert it equals(===)
tovalue
argument.ParametersName Type Argument Description key StringThe key name
value mixedoptional The key value
ReturnsType Description ObjectThe current instance
test .array(['a', 'b']) .hasKey(1) .hasKey(0, 'a') ;
See also -
notHasKey(key, value)
-
Alias of hasNotProperty()
Assert that the
actual
tested array has not akey
. Optionally assert it not equals(!==)
tovalue
argument.ParametersName Type Argument Description key StringThe key name
value mixedoptional The key value
ReturnsType Description ObjectThe current instance
test .array(['a', 'b']) .notHasKey(2) .notHasKey(0, 'b') ;
See also -
hasValue(expected)
-
Assert that the
actual
tested array hasexpected
value.ParametersName Type Description expected mixedThe expected value
ReturnsType Description ObjectThe current instance
test .array([1, 42, 3]) .hasValue(42) ;
See also -
notHasValue(expected)
-
Assert that the
actual
tested array not hasexpected
value.ParametersName Type Description expected mixedThe expected value
ReturnsType Description ObjectThe current instance
test .array([1, 42, 3]) .notHasValue(4) ;
See also -
hasValues(expected)
-
Assert that the
actual
tested array has severalexpected
values passed in an array of expected values.ParametersName Type Description expected ArrayAn array of expected values
ReturnsType Description ObjectThe current instance
test .array([1, 42, 3]) .hasValues([42, 3]) ;
See also -
notHasValues(expected)
-
Assert that the
actual
tested array not has severalexpected
values passed in an array of expected values.ParametersName Type Description expected ArrayAn array of expected values
ReturnsType Description ObjectThe current instance
test .array([1, 42, 3]) .notHasValues([4, 2]) ;
See also -
contains(expected)
-
Assert that the
actual
array to contain something(===)
toexpected
within depth.ParametersName Type Description expected Array[, other_excepted_values] The expected value
ReturnsType 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
actual
array to not contain something(!==)
toexpected
within depth.ParametersName Type Description expected Array[, other_excepted_values] The expected value
ReturnsType 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
actual
tested array is the reverse to theexpected
array. 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.
ReturnsType Description ObjectThe current instance
test .array([1, 2, 3]) .isReverseOf([3, 2, 1]) ;
See also -
isNotReverseOf(expected)
-
Assert that the
actual
tested array is not the reverse to theexpected
array. 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.
ReturnsType Description ObjectThe current instance
test .array([1, 2, 3]) .isNotReverseOf([1, 2, 3]) ;
See also