Value asserter.
The value()
asserter is the generic asserter, it contains almost all the methods of assertions.
This asserter does not assert directly when passing value to value()
method.
It is neutral and accepts any value (undefined, null, boolean, string, function, object, ...).
See also the spec of "value" asserter for more examples.
Example
test.value(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.value({fluent: 'is awesome', deep: [0, 1]}) .is({fluent: 'is awesome', deep: [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.value({fluent: 'is awesome', deep: [0, 1]}) .isNot({fluent: 'is awesome', deep: [0, '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
test.value('1').isEqualTo(1);
-
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.value('foobar').isNotEqualTo([]);
-
isStrictEqualTo(expected)
-
Assert that the
actual
value is strict equal to (===
)expected
value.ParametersName Type Description expected mixedExpected value
ReturnsType Description ObjectThe current instance
test.value(1).isStrictEqualTo(1);
-
isNotStrictEqualTo(expected)
-
Assert that the
actual
value is not identical to (!==
)expected
value.ParametersName Type Description expected mixedExpected value
ReturnsType Description ObjectThe current instance
test.value('1').isNotStrictEqualTo(1);
-
isIdenticalTo(expected)
-
Assert that the
actual
value is identical to (===
)expected
value.ParametersName Type Description expected mixedExpected value
ReturnsType Description ObjectThe current instance
test.value(1).isIdenticalTo(1);
-
isNotIdenticalTo(expected)
-
Assert that the
actual
value is not identical to (!==
)expected
value.ParametersName Type Description expected mixedExpected value
ReturnsType Description ObjectThe current instance
test.value('1').isNotIdenticalTo(1);
-
match(expected)
-
Assert
actual
value to match theexpected
value.ParametersName Type Description expected StringNumberRegExpfunctionExpected matches
ReturnsType Description ObjectThe current instance
// Assert a string value with a expected string test.value('Hello').match('Hello'); // Assert a string value with a RegExp test.value('Hello world !').match(/world/i); // Assert an array value with a RegExp test.value(['a', 'b', 'c']).match(/[a-z]/); // Assert with a function test.value(2014).match(function(it){ return it === 2014; });
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 .value('foobar') .notMatch('some value') .notMatch(/[foo]+bazzz$/) .value(['a', 'b', 'c']) .notMatch(/[d-z]/) .value(10) .notMatch(8) .value(10) .notMatch(function(it){ return it === 42; }) ;
See also -
matchEach(expected)
-
Assert
actual
value to match eachexpected
value.ParametersName Type Description expected ArrayStringNumberRegExpfunctionExpected matches for each
ReturnsType Description ObjectThe current instance
test .value([10, 11, 12]) .matchEach(function(it) { return it >= 10; }) .value('Hello Nico') .matchEach([/hello/i, 'Nico', function(it){ return it === 'Hello Nico!'; }]) ;
See also -
notMatchEach(expected)
-
Assert
actual
value to not match one or severalexpected
value.ParametersName Type Description expected ArrayStringNumberRegExpfunctionExpected value that must not match
ReturnsType Description ObjectThe current instance
test .value([10, 11, 12]) .notMatchEach(function(it) { return it >= 13; }) .value('Hello World') .notMatchEach([/foo/i, 'bad word', function(it){ return it === 'Bye'; }]) ;
See also -
isValid(expected)
-
Alias of
match()
.ParametersName Type Description expected StringNumberRegExpfunctionExpected matches
ReturnsType Description ObjectThe current instance
test .value(42) .isValid(function(actual) { return actual === 42; }) .exception(function(){ test.value(42) .isValid(function(actual) { return actual === 'expected value'; }) }) ;
See also -
isNotValid(expected)
-
Alias of
notMatch()
.ParametersName Type Description expected StringNumberRegExpfunctionExpected matches
ReturnsType Description ObjectThe current instance
test .value(42) .isNotValid(function(actual) { return actual === 44; }) .exception(function(){ test.value(42) .isNotValid(function(actual) { return actual === 42; }) }) ;
See also -
isType(expected)
-
Assert that the type of
actual
value is the givenexpected
value (using typeof operator).ParametersName Type Description expected mixedExpected value
ReturnsType Description ObjectThe current instance
test .value('foobar').isType('string') .value(0).isType('number') .value(1).isType('number') .value(1.2).isType('number') .value('1').isType('string') .value({}).isType('object') .value(undefined).isType('undefined') .value(null).isType('object') .value(true).isType('boolean') .value(false).isType('boolean') ;
-
isNotType(expected)
-
Assert that the type of
actual
value is not the givenexpected
value (using typeof operator).ParametersName Type Description expected mixedExpected value
ReturnsType Description ObjectThe current instance
test .value({}).isNotType('string') .value('0').isNotType('number') .value('1').isNotType('number') .value('1.2').isNotType('number') .value(1).isNotType('string') .value(null).isNotType('undefined') .value(undefined).isNotType('object') .value('true').isNotType('boolean') .value('false').isNotType('boolean') ;
-
isObject()
-
Assert that the type of
actual
value isobject
(using typeof operator).ReturnsType Description ObjectThe current instance
test.value([]).isObject();
-
isArray()
-
Assert that the type of
actual
value isarray
(using typeof operator).ReturnsType Description ObjectThe current instance
test.value([]).isArray();
-
isFunction()
-
Assert that the type of
actual
value isfunction
(using typeof operator).ReturnsType Description ObjectThe current instance
test.value(function(){}).isFunction();
-
isString()
-
Assert that the type of
actual
value isstring
(using typeof operator).ReturnsType Description ObjectThe current instance
test.value('foobar').isString();
-
isNumber()
-
Assert that the type of
actual
value isnumber
(using typeof operator).ReturnsType Description ObjectThe current instance
test.value(42).isNumber();
-
isBool()
-
Alias of
boolean()
.Assert that the type of
actual
value isboolean
(using typeof operator).ReturnsType Description ObjectThe current instance
test.value(false).isBool();
-
isBoolean()
-
Assert that the type of
actual
value isboolean
(using typeof operator).ReturnsType Description ObjectThe current instance
test.value(true).isBoolean();
-
isNull()
-
Assert that the type of
actual
value isnull
(using typeof operator).ReturnsType Description ObjectThe current instance
test.value(null).isNull();
-
isUndefined()
-
Assert that the type of
actual
value isundefined
(using typeof operator).ReturnsType Description ObjectThe current instance
test.value(undefined).isUndefined();
-
isRegExp()
-
Assert that the
actual
value is an instance ofRegExp
.ReturnsType Description ObjectThe current instance
test.value(/[0-9]+/).isRegExp();
-
isNotRegExp()
-
Assert that the
actual
value is not an instance ofRegExp
.ReturnsType Description ObjectThe current instance
test.value(new Date()).isNotRegExp();
-
isDate()
-
Assert that the
actual
value is an instance ofDate
.ReturnsType Description ObjectThe current instance
test.value(new Date()).isDate();
-
isNotDate()
-
Assert that the
actual
value is not an instance ofDate
.ReturnsType Description ObjectThe current instance
test.value(/[0-9]+/).isNotDate();
-
isArguments()
-
Assert that the
actual
value is thearguments
object provided in a function.ReturnsType Description ObjectThe current instance
var fn = function(){ test.value(arguments).isArguments(); }; fn(1, 2, 3);
-
isNotArguments()
-
Assert that the
actual
value is not thearguments
object provided in a function.ReturnsType Description ObjectThe current instance
var fn = function(){ test .value(arguments) .isArguments() .value([1, 2, 3]) .isNotArguments() .value({0:1, 1:2, 2:3}) .isNotArguments() ; }; fn(1, 2, 3);
-
isTrue()
-
Assert that the
actual
value istrue
.ReturnsType Description ObjectThe current instance
test.value(true).isTrue();
-
isNotTrue()
-
Assert that the
actual
value is nottrue
.ReturnsType Description ObjectThe current instance
test .value(false) .isNotTrue() .value(1) .isNotTrue() .value('1') .isNotTrue() .value('true') .isNotTrue() ;
-
isTruthy()
-
Assert that the
actual
value is truthy (!!actual
). Onlynull
,undefined
,0
,false
and""
are falsy in JavaScript. Everything else is truthy.ReturnsType Description ObjectThe current instance
test.value(1).isTruthy();
-
isNotTruthy()
-
Assert that the
actual
value is not truthy. Onlynull
,undefined
,0
,false
and""
are falsy in JavaScript. Everything else is truthy.ReturnsType Description ObjectThe current instance
test.value(0).isNotTruthy();
-
isFalse()
-
Assert that the
actual
value isfalse
.ReturnsType Description ObjectThe current instance
test.value(false).isFalse();
-
isNotFalse()
-
Assert that the
actual
value is notfalse
.ReturnsType Description ObjectThe current instance
test .value(true) .isNotFalse() .value(0) .isNotFalse() .value('0') .isNotFalse() .value('false') .isNotFalse() .value(null) .isNotFalse() .value(undefined) .isNotFalse() ;
-
isFalsy()
-
Assert that the
actual
value is falsy. Onlynull
,undefined
,0
,false
and""
are falsy in JavaScript. Everything else is truthy.ReturnsType Description ObjectThe current instance
test.value(0).isFalsy();
-
isNotFalsy()
-
Assert that the
actual
value is not falsy. Onlynull
,undefined
,0
,false
and""
are falsy in JavaScript. Everything else is truthy.ReturnsType Description ObjectThe current instance
test.value(1).isNotFalsy();
-
isEmpty()
-
Assert that the
actual
value is empty.Checks either the
length
for arrays and strings or the count of enumerable keys. Inherited keys also counted.ReturnsType Description ObjectThe current instance
test.value('').isEmpty();
-
isNotEmpty()
-
Assert that the
actual
value is not empty.Checks either the
length
for arrays and strings or the count of enumerable keys. Inherited keys also counted.ReturnsType Description ObjectThe current instance
test.value('a').isNotEmpty();
-
exists()
-
Assert that the
actual
value is exists and thereby is not null or undefined.ReturnsType Description ObjectThe current instance
test.value('foobar').exists();
-
isError()
-
Assert that the
actual
value (trigger function) throws an instance ofError
(or inherited).ReturnsType Description ObjectThe current instance
// trigger var trigger = function(){ throw new Error("I'm a ninja !") }; test.value(trigger).isError();
-
throws(constructor, expected)
-
Assert that the
actual
value (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
message
property. - A regular expression is matched against the exception's
message
property. - A function (a.k.a. constructor) is used to check if the error is an
instanceof
that constructor. - All other cases of
expected
are left unspecified for now.
Because of how JavaScript works, the function will be called in
null
context (this
). If you want to test an instance method, bind it:test.value(obj.method.bind(obj)).throws()
.ParametersName Type Argument Description constructor StringRegExpfunctionconstructoroptional expected optional ReturnsType Description ObjectThe current instance
// trigger var trigger = function(){ throw new Error("I'm a ninja !") }; test.value(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
-
hasLength(expected)
-
Assert that the
actual
value has a length property equal toexpected
number.ParametersName Type Description expected numberExpected length
ReturnsType Description ObjectThe current instance
test .value([1, 2]) .hasLength(2) .value('Hello Nico') .hasLength(10) ;
-
hasNotLength(expected)
-
Assert that the
actual
value has not a length property equal toexpected
number.ParametersName Type Description expected numberExpected length
ReturnsType Description ObjectThe current instance
test .value([1, 2]) .hasNotLength(1) .value('Hello Nico') .hasNotLength(11) ;
-
isBetween(begin, end)
-
Assert that the
actual
value is betweenbegin
andend
(inclusive).ParametersName Type Description begin numberBegin value
end numberEnd value
ReturnsType Description ObjectThe current instance
test .value(2) .isBetween(2, 4) .value(3) .isBetween(2, 4) .value(4) .isBetween(2, 4) ;
-
isNotBetween(begin, end)
-
Assert that the
actual
value is not betweenbegin
andend
(inclusive).ParametersName Type Description begin numberBegin value
end numberEnd value
ReturnsType Description ObjectThe current instance
test .value(1) .isNotBetween(2, 4) .value(5) .isNotBetween(2, 4) ;
-
isBefore(expected)
-
Alias of
isLessThan()
.Assert that the
actual
value is before theexpected
value.ParametersName Type Description expected mixedExpected value
ReturnsType Description ObjectThe current instance
test.value(new Date(2010, 5, 20)).isBefore(new Date(2012, 2, 28));
-
isAfter(expected)
-
Alias of
isGreaterThan()
.Assert that the
actual
value is after theexpected
value.ParametersName Type Description expected mixedExpected value
ReturnsType Description ObjectThe current instance
test.value(new Date(2012, 2, 28)).isAfter(new Date(2010, 5, 20));
-
isLessThan(expected)
-
Assert that the
actual
value is lesser than theexpected
value.ParametersName Type Description expected mixedExpected value
ReturnsType Description ObjectThe current instance
test.value(1).isLessThan(2);
-
isGreaterThan(expected)
-
Assert that the
actual
value is greater than theexpected
value.ParametersName Type Description expected mixedExpected value
ReturnsType Description ObjectThe current instance
test.value(2).isGreaterThan(1);
-
isApprox(num, delta)
-
Assert that the
actual
value (floating point number) nearnum
withindelta
margin.ParametersName Type Description num numberExpected number
delta numberMargin accepted around
num
ReturnsType Description ObjectThe current instance
test.value(99.98).isApprox(100, 0.02);
-
isInfinite()
-
Assert that the
actual
value isinfinite
.ReturnsType Description ObjectThe current instance
test.value(1/0).isInfinite();
-
isNotInfinite()
-
Assert that the
actual
value is notinfinite
.ReturnsType Description ObjectThe current instance
test.value(1.33333).isNotInfinite();
-
isNaN()
-
Assert that the
actual
value isNaN
.ReturnsType Description ObjectThe current instance
test.value(0/0).isNaN(); test.value(parseInt('foo', 10)).isNaN(); test.value(NaN).isNaN();
See also -
isNotNaN()
-
Assert that the
actual
value is notNaN
.ReturnsType Description ObjectThe current instance
test.value(undefined).isNotNaN(); test.value(false).isNotNaN();
See also -
isEnumerable(property)
-
Assert that the
actual
value has an enumerableproperty
. It will fail if theactual
value lacks theproperty
entirely.This also checks inherited properties in the prototype chain, something which
Object.prototype.propertyIsEnumerable
itself does not do.For checking if a property exists and is non-enumerable, see
isNotEnumerable()
.ParametersName Type Description property StringThe property name
ReturnsType Description ObjectThe current instance
test.value({prop: 'foobar'}).isEnumerable('prop');
See also -
isNotEnumerable(property)
-
Assert that the
actual
value has a non-enumerableproperty
. It will fail if theactual
value lacks theproperty
entirely.This also checks inherited properties in the prototype chain, something which
Object.prototype.propertyIsEnumerable
itself does not do.It's the inverse of
isEnumerable()
.ParametersName Type Description property StringThe property name
ReturnsType Description ObjectThe current instance
test .value(function() {}) .isNotEnumerable('call') .value(Object.create({}, {prop: {enumerable: 0}})) .isNotEnumerable('prop') ;
-
isFrozen()
-
Assert that the
actual
value is frozen withObject.isFrozen
.ReturnsType Description ObjectThe current instance
test.value(Object.freeze({})).isFrozen();
-
isNotFrozen()
-
Assert that the
actual
value is not frozen withObject.isFrozen
.ReturnsType Description ObjectThe current instance
test.value({}).isNotFrozen();
-
isInstanceOf(expected)
-
Assert that the
actual
value is an instance ofexpected
value.Uses
actual instanceof expected
.ParametersName Type Description expected ObjectExpected instance
ReturnsType Description ObjectThe current instance
test.value(new Date()).isInstanceOf(Date);
-
isNotInstanceOf(expected)
-
Assert that the
actual
value is not an instance ofexpected
value.Uses
actual instanceof expected === false
.ParametersName Type Description expected ObjectExpected instance
ReturnsType Description ObjectThe current instance
test.value(new Date()).isNotInstanceOf(RegExp);
-
hasProperty(property, value)
-
Assert that the
actual
tested value hasproperty
. Optionally assert it equals(===)
tovalue
argument.Takes inherited properties into account. To not do so, see
hasOwnProperty()
.ParametersName Type Argument Description property StringThe property name
value mixedoptional The property value
ReturnsType Description ObjectThe current instance
test .value({foo: 'bar'}) .hasProperty('foo') .value({foo: 'bar'}) .hasProperty('foo', 'bar') ;
See also -
hasNotProperty(property, value)
-
Assert that the
actual
tested value has not aproperty
. Optionally assert it not equals(!==)
tovalue
argument.Takes inherited properties into account. To not do so, see
hasNotOwnProperty()
.ParametersName Type Argument Description property StringThe property name
value mixedoptional The property value
ReturnsType Description ObjectThe current instance
test .value({foo: 'bar'}) .hasNotProperty('bar') .value({foo: 'bar'}) .hasNotProperty('foo', 'baz') ;
See also -
hasOwnProperty(property, value)
-
Assert that the
actual
tested value has ownproperty
. Optionally assert it equals(===)
tovalue
argument.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
ReturnsType Description ObjectThe current instance
test .value({foo: 'bar'}) .hasOwnProperty('foo') .value({foo: 'bar'}) .hasOwnProperty('foo', 'bar') ;
See also -
hasNotOwnProperty(property, value)
-
Assert that the
actual
tested value has not ownproperty
. Optionally assert it not equals(!==)
tovalue
argument.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
ReturnsType Description ObjectThe current instance
test .value({foo: 'bar'}) .hasNotOwnProperty('bar') .value({foo: 'bar'}) .hasNotOwnProperty('foo', 'baz') ;
See also -
hasProperties(properties)
-
Assert that the
actual
value 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
ReturnsType Description ObjectThe current instance
test.value({foo: 'bar', bar: 'huhu', other: 'vroom'}) .hasProperties(['other', 'bar', 'foo']);
-
hasNotProperties(properties)
-
Assert that the
actual
value 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
ReturnsType Description ObjectThe current instance
test.value({foo: 'bar', bar: 'huhu', other: 'vroom'}) .hasNotProperties(['other', 'foo']);
-
hasOwnProperties(properties)
-
Assert that the
actual
value has only the expected enumerableproperties
of 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
ReturnsType Description ObjectThe current instance
test.value({foo: 'bar', bar: 'huhu', other: 'vroom'}) .hasOwnProperties(['other', 'bar', 'foo']);
-
hasKey(key, value)
-
Alias of hasProperty()
Assert that the
actual
tested value has akey
. Optionally assert it equals(===)
tovalue
argument.Takes inherited properties into account. To not do so, see
hasOwnProperty()
.ParametersName Type Argument Description key StringThe key name
value mixedoptional The key value
ReturnsType Description ObjectThe current instance
test .value({foo: 'bar'}) .hasKey('foo') .value({foo: 'bar'}) .hasKey('foo', 'bar') ;
See also -
notHasKey(key, value)
-
Alias of hasNotProperty()
Assert that the
actual
tested value has not akey
. Optionally assert it not equals(!==)
tovalue
argument.Takes inherited properties into account. To not do so, see
hasNotOwnProperty()
.ParametersName Type Argument Description key StringThe key name
value mixedoptional The key value
ReturnsType Description ObjectThe current instance
test .value({foo: 'bar'}) .notHasKey('bar') .value({foo: 'bar'}) .notHasKey('foo', 'baz') ;
See also -
hasKeys(keys)
-
Alias of hasProperties()
Assert that the
actual
value 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
ReturnsType Description ObjectThe current instance
test.value({foo: 'bar', bar: 'huhu', other: 'vroom'}) .hasKeys(['other', 'bar', 'foo']);
-
notHasKeys(keys)
-
Alias of hasNotProperties()
Assert that the
actual
value 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
ReturnsType Description ObjectThe current instance
test.value({foo: 'bar', bar: 'huhu', other: 'vroom'}) .notHasKeys(['other', 'foo']);
-
hasValue(expected)
-
Assert that the
actual
tested value hasexpected
value.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
ReturnsType Description ObjectThe current instance
test .value('Hello, Nico!') .hasValue('Nico') .value([1, 42, 3]) .hasValue(42) .value({life: 42, love: 69}) .hasValue(42) ;
See also -
notHasValue(expected)
-
Assert that the
actual
tested value not hasexpected
value.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
ReturnsType Description ObjectThe current instance
test .value('Hello, Nico!') .notHasValue('Bye') .value([1, 42, 3]) .notHasValue(4) .value({life: 42, love: 69}) .notHasValue(4) ;
See also -
hasValues(expected)
-
Assert that the
actual
tested value 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.value([1, 42, 3]).hasValues([42, 3]);
See also -
notHasValues(expected)
-
Assert that the
actual
tested value 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.value([1, 42, 3]).notHasValues([4, 2]);
See also -
contains(expected)
-
Assert that the
actual
value to contain something(===)
toexpected
within depth.ParametersName Type Argument Description expected mixedrepeatable One or more expected value.
ReturnsType Description ObjectThe current instance
test .value('hello boy') .contains('boy') .value('KISS principle : Keep it Simple, Stupid') .contains('Simple', 'principle', ':') .value([1,2,3]) .contains([3]) .value([1,2,3]) .contains([1, 3]) .value([1,2,3]) .contains([3, 1, 2]) .value({ a: { b: 10 }, b: { c: 10, d: 11, a: { b: 10, c: 11} }}) .contains({ a: { b: 10 }, b: { c: 10, a: { c: 11 }}}) .value([1, 2, 3, { a: { b: { d: 12 }}}]) .contains([2], [1, 2], [{ a: { b: {d: 12}}}]) .value([[1],[2],[3]]) .contains([[3]]) .value([[1],[2],[3, 4]]) .contains([[3]]) .value([{a: 'a'}, {b: 'b', c: 'c'}]) .contains([{a: 'a'}], [{b: 'b'}]) .exception(function(){ test.value([{a: 'a'}, {b: 'b', c: 'c'}]) .contains([{a: 'a'}], [{b: 'c'}]); }) ;
See also -
notContains(expected)
-
Assert that the
actual
value to not contain something(!==)
toexpected
within depth.ParametersName Type Argument Description expected mixedrepeatable One or more expected value.
ReturnsType Description ObjectThe current instance
test .value('hello boy') .notContains('bye') .value([[1],[2],[3, 4]]) .notContains([[0]]) .value([{a: 'a'}, {b: 'b', c: 'c'}]) .notContains([{a: 'b'}], [{c: 'b'}]) .exception(function(){ test.value([{a: 'a'}, {b: 'b', c: 'c'}]) .notContains([{a: 'a'}, {c: 'c'}]); }) ;
See also -
isReverseOf(expected)
-
Assert that the
actual
tested value is the reverse array 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 .value([1, 2, 3]) .isReverseOf([3, 2, 1]) ;
See also -
isNotReverseOf(expected)
-
Assert that the
actual
tested value is not the reverse array 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 .value([1, 2, 2, 3]) .isNotReverseOf([3, 2, 1]) ;
See also -
startsWith(str)
-
Assert that the
actual
value starts withstr
.ParametersName Type Description str StringExpected
string
valueReturnsType Description ObjectThe current instance
test.value('foobar').startsWith('foo');
-
notStartsWith(str)
-
Assert that the
actual
value not starts withstr
.ParametersName Type Description str StringExpected
string
valueReturnsType Description ObjectThe current instance
test.value('foobar').notStartsWith('bar');
-
endsWith(str)
-
Assert that the
actual
value ends withstr
.ParametersName Type Description str StringExpected
string
valueReturnsType Description ObjectThe current instance
test.value('foobar').endsWith('bar');
-
notEndsWith(str)
-
Assert that the
actual
value not ends withstr
.ParametersName Type Description str StringExpected
string
valueReturnsType Description ObjectThe current instance
test.value('foobar').notEndsWith('foo');
-
hasHttpStatus(code)
-
Assert that the
actual
value has a given HTTP statuscode
.ParametersName Type Description code StringExpected
code
valueReturnsType Description ObjectThe current instance
// Structure of a request object. // By example, provided by Express framework and other modules. var req = { headers: { 'content-type': 'application/json', }, statusCode: 200 }; test.value(req).hasHttpStatus(200);
-
notHasHttpStatus(code)
-
Assert that the
actual
value not has a given HTTP statuscode
.ParametersName Type Description code StringExpected
code
valueReturnsType Description ObjectThe current instance
// Structure of a request object. // By example, provided by Express framework and other modules. var req = { headers: { 'content-type': 'application/json', }, statusCode: 200 }; test.value(req).notHasHttpStatus(404);
-
hasHeader(field, value)
-
Assert that the
actual
value has a given headerfield
and optionalvalue
are present.ParametersName Type Argument Description field StringField name
value StringNumberoptional Header value
ReturnsType Description ObjectThe current instance
// Structure of a request object. // By example, provided by Express framework and other modules. var req = { headers: { 'content-type': 'application/json' } }; test .value(req) .hasHeader('content-type') .hasHeader('content-type', 'application/json') ;
-
notHasHeader(field, value)
-
Assert that the
actual
value not has a given headerfield
and optionalvalue
are not present.ParametersName Type Argument Description field StringField name
value StringNumberoptional Header value
ReturnsType Description ObjectThe current instance
// Structure of a request object. // By example, provided by Express framework and other modules. var req = { headers: { 'content-type': 'application/json' } }; test .value(req) .notHasHeader('charset') .notHasHeader('content-type', 'text/html') // other test cases .value({}) .notHasHeader('charset') .notHasHeader('content-type', 'text/html') .value({headers: {}}) .notHasHeader('charset') .notHasHeader('content-type', 'text/html') .error(function(){ test.value(req).notHasHeader('content-type'); }) ;
-
hasHeaderJson()
-
Assert that the
actual
value has a JSON header(application/json)
.ReturnsType Description ObjectThe current instance
// Structure of a request object. // By example, provided by Express framework and other modules. var req = { headers: { 'content-type': 'application/json' } }; test.value(req).hasHeaderJson(); req.headers['content-type'] = 'application/json; charset=utf-8'; test.value(req).hasHeaderJson();
-
notHasHeaderJson()
-
Assert that the
actual
value not has a JSON header(application/json)
.ReturnsType Description ObjectThe current instance
// Structure of a request object. // By example, provided by Express framework and other modules. var req = { headers: { 'content-type': 'text/html' } }; test.value(req).notHasHeaderJson();
-
hasHeaderHtml()
-
Assert that the
actual
value has a HTML header(text/html)
.ReturnsType Description ObjectThe current instance
// Structure of a request object. // By example, provided by Express framework and other modules. var req = { headers: { 'content-type': 'text/html' } }; test.value(req).hasHeaderHtml(); req.headers['content-type'] = 'text/html; charset=utf-8'; test.value(req).hasHeaderHtml();
-
notHasHeaderHtml()
-
Assert that the
actual
value not has a HTML header(text/html)
.ReturnsType Description ObjectThe current instance
// Structure of a request object. // By example, provided by Express framework and other modules. var req = { headers: { 'content-type': 'application/json' } }; test.value(req).notHasHeaderHtml();