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
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.value({fluent: 'is awesome', deep: [0, 1]}) .is({fluent: 'is awesome', deep: [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.value({fluent: 'is awesome', deep: [0, 1]}) .isNot({fluent: 'is awesome', deep: [0, '1']});
See also -
isEqualTo(expected)
-
Assert that the
actualvalue is equal to (==) theexpectedvalue.ParametersName Type Description expected mixedExpected value
ExampleReturnsType Description ObjectThe current instance
test.value('1').isEqualTo(1); -
isNotEqualTo(expected)
-
Assert that the
actualvalue is not equal to (!=) theexpectedvalue.ParametersName Type Description expected mixedExpected value
ExampleReturnsType Description ObjectThe current instance
test.value('foobar').isNotEqualTo([]); -
isStrictEqualTo(expected)
-
Assert that the
actualvalue is strict equal to (===)expectedvalue.ParametersName Type Description expected mixedExpected value
ExampleReturnsType Description ObjectThe current instance
test.value(1).isStrictEqualTo(1); -
isNotStrictEqualTo(expected)
-
Assert that the
actualvalue is not identical to (!==)expectedvalue.ParametersName Type Description expected mixedExpected value
ExampleReturnsType Description ObjectThe current instance
test.value('1').isNotStrictEqualTo(1); -
isIdenticalTo(expected)
-
Assert that the
actualvalue is identical to (===)expectedvalue.ParametersName Type Description expected mixedExpected value
ExampleReturnsType Description ObjectThe current instance
test.value(1).isIdenticalTo(1); -
isNotIdenticalTo(expected)
-
Assert that the
actualvalue is not identical to (!==)expectedvalue.ParametersName Type Description expected mixedExpected value
ExampleReturnsType Description ObjectThe current instance
test.value('1').isNotIdenticalTo(1); -
match(expected)
-
Assert
actualvalue to match theexpectedvalue.ParametersName Type Description expected StringNumberRegExpfunctionExpected matches
ExampleReturnsType 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
actualvalue to not match theexpectedvalue.ParametersName Type Description expected StringNumberRegExpfunctionExpected value that must not match
ExampleReturnsType 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
actualvalue to match eachexpectedvalue.ParametersName Type Description expected ArrayStringNumberRegExpfunctionExpected matches for each
ExampleReturnsType 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
actualvalue to not match one or severalexpectedvalue.ParametersName Type Description expected ArrayStringNumberRegExpfunctionExpected value that must not match
ExampleReturnsType 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
ExampleReturnsType 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
ExampleReturnsType 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
actualvalue is the givenexpectedvalue (using typeof operator).ParametersName Type Description expected mixedExpected value
ExampleReturnsType 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
actualvalue is not the givenexpectedvalue (using typeof operator).ParametersName Type Description expected mixedExpected value
ExampleReturnsType 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
actualvalue isobject(using typeof operator).ExampleReturnsType Description ObjectThe current instance
test.value([]).isObject(); -
isArray()
-
Assert that the type of
actualvalue isarray(using typeof operator).ExampleReturnsType Description ObjectThe current instance
test.value([]).isArray(); -
isFunction()
-
Assert that the type of
actualvalue isfunction(using typeof operator).ExampleReturnsType Description ObjectThe current instance
test.value(function(){}).isFunction(); -
isString()
-
Assert that the type of
actualvalue isstring(using typeof operator).ExampleReturnsType Description ObjectThe current instance
test.value('foobar').isString(); -
isNumber()
-
Assert that the type of
actualvalue isnumber(using typeof operator).ExampleReturnsType Description ObjectThe current instance
test.value(42).isNumber(); -
isBool()
-
Alias of
boolean().Assert that the type of
actualvalue isboolean(using typeof operator).ExampleReturnsType Description ObjectThe current instance
test.value(false).isBool(); -
isBoolean()
-
Assert that the type of
actualvalue isboolean(using typeof operator).ExampleReturnsType Description ObjectThe current instance
test.value(true).isBoolean(); -
isNull()
-
Assert that the type of
actualvalue isnull(using typeof operator).ExampleReturnsType Description ObjectThe current instance
test.value(null).isNull(); -
isUndefined()
-
Assert that the type of
actualvalue isundefined(using typeof operator).ExampleReturnsType Description ObjectThe current instance
test.value(undefined).isUndefined(); -
isRegExp()
-
Assert that the
actualvalue is an instance ofRegExp.ExampleReturnsType Description ObjectThe current instance
test.value(/[0-9]+/).isRegExp(); -
isNotRegExp()
-
Assert that the
actualvalue is not an instance ofRegExp.ExampleReturnsType Description ObjectThe current instance
test.value(new Date()).isNotRegExp(); -
isDate()
-
Assert that the
actualvalue is an instance ofDate.ExampleReturnsType Description ObjectThe current instance
test.value(new Date()).isDate(); -
isNotDate()
-
Assert that the
actualvalue is not an instance ofDate.ExampleReturnsType Description ObjectThe current instance
test.value(/[0-9]+/).isNotDate(); -
isArguments()
-
Assert that the
actualvalue is theargumentsobject provided in a function.ExampleReturnsType Description ObjectThe current instance
var fn = function(){ test.value(arguments).isArguments(); }; fn(1, 2, 3); -
isNotArguments()
-
Assert that the
actualvalue is not theargumentsobject provided in a function.ExampleReturnsType 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
actualvalue istrue.ExampleReturnsType Description ObjectThe current instance
test.value(true).isTrue(); -
isNotTrue()
-
Assert that the
actualvalue is nottrue.ExampleReturnsType Description ObjectThe current instance
test .value(false) .isNotTrue() .value(1) .isNotTrue() .value('1') .isNotTrue() .value('true') .isNotTrue() ; -
isTruthy()
-
Assert that the
actualvalue is truthy (!!actual). Onlynull,undefined,0,falseand""are falsy in JavaScript. Everything else is truthy.ExampleReturnsType Description ObjectThe current instance
test.value(1).isTruthy(); -
isNotTruthy()
-
Assert that the
actualvalue is not truthy. Onlynull,undefined,0,falseand""are falsy in JavaScript. Everything else is truthy.ExampleReturnsType Description ObjectThe current instance
test.value(0).isNotTruthy(); -
isFalse()
-
Assert that the
actualvalue isfalse.ExampleReturnsType Description ObjectThe current instance
test.value(false).isFalse(); -
isNotFalse()
-
Assert that the
actualvalue is notfalse.ExampleReturnsType 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
actualvalue is falsy. Onlynull,undefined,0,falseand""are falsy in JavaScript. Everything else is truthy.ExampleReturnsType Description ObjectThe current instance
test.value(0).isFalsy(); -
isNotFalsy()
-
Assert that the
actualvalue is not falsy. Onlynull,undefined,0,falseand""are falsy in JavaScript. Everything else is truthy.ExampleReturnsType Description ObjectThe current instance
test.value(1).isNotFalsy(); -
isEmpty()
-
Assert that the
actualvalue is empty.Checks either the
lengthfor arrays and strings or the count of enumerable keys. Inherited keys also counted.ExampleReturnsType Description ObjectThe current instance
test.value('').isEmpty(); -
isNotEmpty()
-
Assert that the
actualvalue is not empty.Checks either the
lengthfor arrays and strings or the count of enumerable keys. Inherited keys also counted.ExampleReturnsType Description ObjectThe current instance
test.value('a').isNotEmpty(); -
exists()
-
Assert that the
actualvalue is exists and thereby is not null or undefined.ExampleReturnsType Description ObjectThe current instance
test.value('foobar').exists(); -
isError()
-
Assert that the
actualvalue (trigger function) throws an instance ofError(or inherited).ExampleReturnsType 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
actualvalue (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
messageproperty. - A regular expression is matched against the exception's
messageproperty. - A function (a.k.a. constructor) is used to check if the error is an
instanceofthat constructor. - All other cases of
expectedare left unspecified for now.
Because of how JavaScript works, the function will be called in
nullcontext (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 ExampleReturnsType 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
actualvalue has a length property equal toexpectednumber.ParametersName Type Description expected numberExpected length
ExampleReturnsType Description ObjectThe current instance
test .value([1, 2]) .hasLength(2) .value('Hello Nico') .hasLength(10) ; -
hasNotLength(expected)
-
Assert that the
actualvalue has not a length property equal toexpectednumber.ParametersName Type Description expected numberExpected length
ExampleReturnsType Description ObjectThe current instance
test .value([1, 2]) .hasNotLength(1) .value('Hello Nico') .hasNotLength(11) ; -
isBetween(begin, end)
-
Assert that the
actualvalue is betweenbeginandend(inclusive).ParametersName Type Description begin numberBegin value
end numberEnd value
ExampleReturnsType 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
actualvalue is not betweenbeginandend(inclusive).ParametersName Type Description begin numberBegin value
end numberEnd value
ExampleReturnsType Description ObjectThe current instance
test .value(1) .isNotBetween(2, 4) .value(5) .isNotBetween(2, 4) ; -
isBefore(expected)
-
Alias of
isLessThan().Assert that the
actualvalue is before theexpectedvalue.ParametersName Type Description expected mixedExpected value
ExampleReturnsType 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
actualvalue is after theexpectedvalue.ParametersName Type Description expected mixedExpected value
ExampleReturnsType Description ObjectThe current instance
test.value(new Date(2012, 2, 28)).isAfter(new Date(2010, 5, 20)); -
isLessThan(expected)
-
Assert that the
actualvalue is lesser than theexpectedvalue.ParametersName Type Description expected mixedExpected value
ExampleReturnsType Description ObjectThe current instance
test.value(1).isLessThan(2); -
isGreaterThan(expected)
-
Assert that the
actualvalue is greater than theexpectedvalue.ParametersName Type Description expected mixedExpected value
ExampleReturnsType Description ObjectThe current instance
test.value(2).isGreaterThan(1); -
isApprox(num, delta)
-
Assert that the
actualvalue (floating point number) nearnumwithindeltamargin.ParametersName Type Description num numberExpected number
delta numberMargin accepted around
numExampleReturnsType Description ObjectThe current instance
test.value(99.98).isApprox(100, 0.02); -
isInfinite()
-
Assert that the
actualvalue isinfinite.ExampleReturnsType Description ObjectThe current instance
test.value(1/0).isInfinite(); -
isNotInfinite()
-
Assert that the
actualvalue is notinfinite.ExampleReturnsType Description ObjectThe current instance
test.value(1.33333).isNotInfinite(); -
isNaN()
-
Assert that the
actualvalue isNaN.ExampleReturnsType 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
actualvalue is notNaN.ExampleReturnsType Description ObjectThe current instance
test.value(undefined).isNotNaN(); test.value(false).isNotNaN();
See also -
isEnumerable(property)
-
Assert that the
actualvalue 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.value({prop: 'foobar'}).isEnumerable('prop');
See also -
isNotEnumerable(property)
-
Assert that the
actualvalue 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 .value(function() {}) .isNotEnumerable('call') .value(Object.create({}, {prop: {enumerable: 0}})) .isNotEnumerable('prop') ; -
isFrozen()
-
Assert that the
actualvalue is frozen withObject.isFrozen.ExampleReturnsType Description ObjectThe current instance
test.value(Object.freeze({})).isFrozen(); -
isNotFrozen()
-
Assert that the
actualvalue is not frozen withObject.isFrozen.ExampleReturnsType Description ObjectThe current instance
test.value({}).isNotFrozen(); -
isInstanceOf(expected)
-
Assert that the
actualvalue is an instance ofexpectedvalue.Uses
actual instanceof expected.ParametersName Type Description expected ObjectExpected instance
ExampleReturnsType Description ObjectThe current instance
test.value(new Date()).isInstanceOf(Date); -
isNotInstanceOf(expected)
-
Assert that the
actualvalue is not an instance ofexpectedvalue.Uses
actual instanceof expected === false.ParametersName Type Description expected ObjectExpected instance
ExampleReturnsType Description ObjectThe current instance
test.value(new Date()).isNotInstanceOf(RegExp); -
hasProperty(property, value)
-
Assert that the
actualtested value 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 .value({foo: 'bar'}) .hasProperty('foo') .value({foo: 'bar'}) .hasProperty('foo', 'bar') ;
See also -
hasNotProperty(property, value)
-
Assert that the
actualtested value 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 .value({foo: 'bar'}) .hasNotProperty('bar') .value({foo: 'bar'}) .hasNotProperty('foo', 'baz') ;
See also -
hasOwnProperty(property, value)
-
Assert that the
actualtested value 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 .value({foo: 'bar'}) .hasOwnProperty('foo') .value({foo: 'bar'}) .hasOwnProperty('foo', 'bar') ;
See also -
hasNotOwnProperty(property, value)
-
Assert that the
actualtested value 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 .value({foo: 'bar'}) .hasNotOwnProperty('bar') .value({foo: 'bar'}) .hasNotOwnProperty('foo', 'baz') ;
See also -
hasProperties(properties)
-
Assert that the
actualvalue 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.value({foo: 'bar', bar: 'huhu', other: 'vroom'}) .hasProperties(['other', 'bar', 'foo']); -
hasNotProperties(properties)
-
Assert that the
actualvalue 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.value({foo: 'bar', bar: 'huhu', other: 'vroom'}) .hasNotProperties(['other', 'foo']); -
hasOwnProperties(properties)
-
Assert that the
actualvalue 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.value({foo: 'bar', bar: 'huhu', other: 'vroom'}) .hasOwnProperties(['other', 'bar', 'foo']); -
hasKey(key, value)
-
Alias of hasProperty()Assert that the
actualtested value 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 .value({foo: 'bar'}) .hasKey('foo') .value({foo: 'bar'}) .hasKey('foo', 'bar') ;
See also -
notHasKey(key, value)
-
Alias of hasNotProperty()Assert that the
actualtested value 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 .value({foo: 'bar'}) .notHasKey('bar') .value({foo: 'bar'}) .notHasKey('foo', 'baz') ;
See also -
hasKeys(keys)
-
Alias of hasProperties()Assert that the
actualvalue 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.value({foo: 'bar', bar: 'huhu', other: 'vroom'}) .hasKeys(['other', 'bar', 'foo']); -
notHasKeys(keys)
-
Alias of hasNotProperties()Assert that the
actualvalue 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.value({foo: 'bar', bar: 'huhu', other: 'vroom'}) .notHasKeys(['other', 'foo']); -
hasValue(expected)
-
Assert that the
actualtested value 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 .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
actualtested value 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 .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
actualtested value has severalexpectedvalues passed in an array of expected values.ParametersName Type Description expected ArrayAn array of expected values
ExampleReturnsType Description ObjectThe current instance
test.value([1, 42, 3]).hasValues([42, 3]);
See also -
notHasValues(expected)
-
Assert that the
actualtested value 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.value([1, 42, 3]).notHasValues([4, 2]);
See also -
contains(expected)
-
Assert that the
actualvalue to contain something(===)toexpectedwithin depth.ParametersName Type Argument Description expected mixedrepeatable One or more expected value.
ExampleReturnsType 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
actualvalue to not contain something(!==)toexpectedwithin depth.ParametersName Type Argument Description expected mixedrepeatable One or more expected value.
ExampleReturnsType 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
actualtested value is the reverse array 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 .value([1, 2, 3]) .isReverseOf([3, 2, 1]) ;
See also -
isNotReverseOf(expected)
-
Assert that the
actualtested value is not the reverse array 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 .value([1, 2, 2, 3]) .isNotReverseOf([3, 2, 1]) ;
See also -
startsWith(str)
-
Assert that the
actualvalue starts withstr.ParametersName Type Description str StringExpected
stringvalueExampleReturnsType Description ObjectThe current instance
test.value('foobar').startsWith('foo'); -
notStartsWith(str)
-
Assert that the
actualvalue not starts withstr.ParametersName Type Description str StringExpected
stringvalueExampleReturnsType Description ObjectThe current instance
test.value('foobar').notStartsWith('bar'); -
endsWith(str)
-
Assert that the
actualvalue ends withstr.ParametersName Type Description str StringExpected
stringvalueExampleReturnsType Description ObjectThe current instance
test.value('foobar').endsWith('bar'); -
notEndsWith(str)
-
Assert that the
actualvalue not ends withstr.ParametersName Type Description str StringExpected
stringvalueExampleReturnsType Description ObjectThe current instance
test.value('foobar').notEndsWith('foo'); -
hasHttpStatus(code)
-
Assert that the
actualvalue has a given HTTP statuscode.ParametersName Type Description code StringExpected
codevalueExampleReturnsType 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
actualvalue not has a given HTTP statuscode.ParametersName Type Description code StringExpected
codevalueExampleReturnsType 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
actualvalue has a given headerfieldand optionalvalueare present.ParametersName Type Argument Description field StringField name
value StringNumberoptional Header value
ExampleReturnsType 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
actualvalue not has a given headerfieldand optionalvalueare not present.ParametersName Type Argument Description field StringField name
value StringNumberoptional Header value
ExampleReturnsType 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
actualvalue has a JSON header(application/json).ExampleReturnsType 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
actualvalue not has a JSON header(application/json).ExampleReturnsType 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
actualvalue has a HTML header(text/html).ExampleReturnsType 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
actualvalue not has a HTML header(text/html).ExampleReturnsType 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();

