value

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.
  • NaNs 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.

Parameters
Name Type Description
expected
mixed

Expected value

Returns
Type Description
Object

The current instance

Example
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.
  • NaNs 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.

Parameters
Name Type Description
expected
mixed

Expected value

Returns
Type Description
Object

The current instance

Example
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 (==) the expected value.

Parameters
Name Type Description
expected
mixed

Expected value

Returns
Type Description
Object

The current instance

Example
test.value('1').isEqualTo(1);

isNotEqualTo(expected)


Assert that the actual value is not equal to (!=) the expected value.

Parameters
Name Type Description
expected
mixed

Expected value

Returns
Type Description
Object

The current instance

Example
test.value('foobar').isNotEqualTo([]);

isStrictEqualTo(expected)


Assert that the actual value is strict equal to (===) expected value.

Parameters
Name Type Description
expected
mixed

Expected value

Returns
Type Description
Object

The current instance

Example
test.value(1).isStrictEqualTo(1);

isNotStrictEqualTo(expected)


Assert that the actual value is not identical to (!==) expected value.

Parameters
Name Type Description
expected
mixed

Expected value

Returns
Type Description
Object

The current instance

Example
test.value('1').isNotStrictEqualTo(1);

isIdenticalTo(expected)


Assert that the actual value is identical to (===) expected value.

Parameters
Name Type Description
expected
mixed

Expected value

Returns
Type Description
Object

The current instance

Example
test.value(1).isIdenticalTo(1);

isNotIdenticalTo(expected)


Assert that the actual value is not identical to (!==) expected value.

Parameters
Name Type Description
expected
mixed

Expected value

Returns
Type Description
Object

The current instance

Example
test.value('1').isNotIdenticalTo(1);

match(expected)


Assert actual value to match the expected value.

Parameters
Name Type Description
expected
String
Number
RegExp
function

Expected matches

Returns
Type Description
Object

The current instance

Example
// 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 the expected value.

Parameters
Name Type Description
expected
String
Number
RegExp
function

Expected value that must not match

Returns
Type Description
Object

The current instance

Example
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 each expected value.

Parameters
Name Type Description
expected
Array
String
Number
RegExp
function

Expected matches for each

Returns
Type Description
Object

The current instance

Example
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 several expected value.

Parameters
Name Type Description
expected
Array
String
Number
RegExp
function

Expected value that must not match

Returns
Type Description
Object

The current instance

Example
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().

Parameters
Name Type Description
expected
String
Number
RegExp
function

Expected matches

Returns
Type Description
Object

The current instance

Example
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().

Parameters
Name Type Description
expected
String
Number
RegExp
function

Expected matches

Returns
Type Description
Object

The current instance

Example
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 given expected value (using typeof operator).

Parameters
Name Type Description
expected
mixed

Expected value

Returns
Type Description
Object

The current instance

Example
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 given expected value (using typeof operator).

Parameters
Name Type Description
expected
mixed

Expected value

Returns
Type Description
Object

The current instance

Example
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 is object (using typeof operator).

Returns
Type Description
Object

The current instance

Example
test.value([]).isObject();

isArray()


Assert that the type of actual value is array (using typeof operator).

Returns
Type Description
Object

The current instance

Example
test.value([]).isArray();

isFunction()


Assert that the type of actual value is function (using typeof operator).

Returns
Type Description
Object

The current instance

Example
test.value(function(){}).isFunction();

isString()


Assert that the type of actual value is string (using typeof operator).

Returns
Type Description
Object

The current instance

Example
test.value('foobar').isString();

isNumber()


Assert that the type of actual value is number (using typeof operator).

Returns
Type Description
Object

The current instance

Example
test.value(42).isNumber();

isBool()


Alias of boolean().

Assert that the type of actual value is boolean (using typeof operator).

Returns
Type Description
Object

The current instance

Example
test.value(false).isBool();

isBoolean()


Assert that the type of actual value is boolean (using typeof operator).

Returns
Type Description
Object

The current instance

Example
test.value(true).isBoolean();

isNull()


Assert that the type of actual value is null (using typeof operator).

Returns
Type Description
Object

The current instance

Example
test.value(null).isNull();

isUndefined()


Assert that the type of actual value is undefined (using typeof operator).

Returns
Type Description
Object

The current instance

Example
test.value(undefined).isUndefined();

isRegExp()


Assert that the actual value is an instance of RegExp.

Returns
Type Description
Object

The current instance

Example
test.value(/[0-9]+/).isRegExp();

isNotRegExp()


Assert that the actual value is not an instance of RegExp.

Returns
Type Description
Object

The current instance

Example
test.value(new Date()).isNotRegExp();

isDate()


Assert that the actual value is an instance of Date.

Returns
Type Description
Object

The current instance

Example
test.value(new Date()).isDate();

isNotDate()


Assert that the actual value is not an instance of Date.

Returns
Type Description
Object

The current instance

Example
test.value(/[0-9]+/).isNotDate();

isArguments()


Assert that the actual value is the arguments object provided in a function.

Returns
Type Description
Object

The current instance

Example
var fn = function(){
  test.value(arguments).isArguments();
};

fn(1, 2, 3);

isNotArguments()


Assert that the actual value is not the arguments object provided in a function.

Returns
Type Description
Object

The current instance

Example
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 is true.

Returns
Type Description
Object

The current instance

Example
test.value(true).isTrue();

isNotTrue()


Assert that the actual value is not true.

Returns
Type Description
Object

The current instance

Example
test
  .value(false)
    .isNotTrue()

  .value(1)
    .isNotTrue()

  .value('1')
    .isNotTrue()

  .value('true')
    .isNotTrue()
;

isTruthy()


Assert that the actual value is truthy (!!actual). Only null, undefined, 0, false and "" are falsy in JavaScript. Everything else is truthy.

Returns
Type Description
Object

The current instance

Example
test.value(1).isTruthy();

isNotTruthy()


Assert that the actual value is not truthy. Only null, undefined, 0, false and "" are falsy in JavaScript. Everything else is truthy.

Returns
Type Description
Object

The current instance

Example
test.value(0).isNotTruthy();

isFalse()


Assert that the actual value is false.

Returns
Type Description
Object

The current instance

Example
test.value(false).isFalse();

isNotFalse()


Assert that the actual value is not false.

Returns
Type Description
Object

The current instance

Example
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. Only null, undefined, 0, false and "" are falsy in JavaScript. Everything else is truthy.

Returns
Type Description
Object

The current instance

Example
test.value(0).isFalsy();

isNotFalsy()


Assert that the actual value is not falsy. Only null, undefined, 0, false and "" are falsy in JavaScript. Everything else is truthy.

Returns
Type Description
Object

The current instance

Example
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.

Returns
Type Description
Object

The current instance

Example
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.

Returns
Type Description
Object

The current instance

Example
test.value('a').isNotEmpty();

exists()


Assert that the actual value is exists and thereby is not null or undefined.

Returns
Type Description
Object

The current instance

Example
test.value('foobar').exists();

isError()


Assert that the actual value (trigger function) throws an instance of Error (or inherited).

Returns
Type Description
Object

The current instance

Example
// 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().

Parameters
Name Type Argument Description
constructor
String
RegExp
function
constructor
optional 
expected optional 
Returns
Type Description
Object

The current instance

Example
// 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

hasLength(expected)


Assert that the actual value has a length property equal to expected number.

Parameters
Name Type Description
expected
number

Expected length

Returns
Type Description
Object

The current instance

Example
test
  .value([1, 2])
    .hasLength(2)

  .value('Hello Nico')
    .hasLength(10)
;

hasNotLength(expected)


Assert that the actual value has not a length property equal to expected number.

Parameters
Name Type Description
expected
number

Expected length

Returns
Type Description
Object

The current instance

Example
test
  .value([1, 2])
    .hasNotLength(1)

  .value('Hello Nico')
    .hasNotLength(11)
;

isBetween(begin, end)


Assert that the actual value is between begin and end (inclusive).

Parameters
Name Type Description
begin
number

Begin value

end
number

End value

Returns
Type Description
Object

The current instance

Example
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 between begin and end (inclusive).

Parameters
Name Type Description
begin
number

Begin value

end
number

End value

Returns
Type Description
Object

The current instance

Example
test
  .value(1)
    .isNotBetween(2, 4)

  .value(5)
    .isNotBetween(2, 4)
;

isBefore(expected)


Alias of isLessThan().

Assert that the actual value is before the expected value.

Parameters
Name Type Description
expected
mixed

Expected value

Returns
Type Description
Object

The current instance

Example
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 the expected value.

Parameters
Name Type Description
expected
mixed

Expected value

Returns
Type Description
Object

The current instance

Example
test.value(new Date(2012, 2, 28)).isAfter(new Date(2010, 5, 20));

isLessThan(expected)


Assert that the actual value is lesser than the expected value.

Parameters
Name Type Description
expected
mixed

Expected value

Returns
Type Description
Object

The current instance

Example
test.value(1).isLessThan(2);

isGreaterThan(expected)


Assert that the actual value is greater than the expected value.

Parameters
Name Type Description
expected
mixed

Expected value

Returns
Type Description
Object

The current instance

Example
test.value(2).isGreaterThan(1);

isApprox(num, delta)


Assert that the actual value (floating point number) near num within delta margin.

Parameters
Name Type Description
num
number

Expected number

delta
number

Margin accepted around num

Returns
Type Description
Object

The current instance

Example
test.value(99.98).isApprox(100, 0.02);

isInfinite()


Assert that the actual value is infinite.

Returns
Type Description
Object

The current instance

Example
test.value(1/0).isInfinite();

isNotInfinite()


Assert that the actual value is not infinite.

Returns
Type Description
Object

The current instance

Example
test.value(1.33333).isNotInfinite();

isNaN()


Assert that the actual value is NaN.

Returns
Type Description
Object

The current instance

Example
test.value(0/0).isNaN();
test.value(parseInt('foo', 10)).isNaN();
test.value(new Number(NaN)).isNaN();

See also

isNotNaN()


Assert that the actual value is not NaN.

Returns
Type Description
Object

The current instance

Example
test.value(undefined).isNotNaN();
test.value(false).isNotNaN();

See also

isEnumerable(property)


Assert that the actual value has an enumerable property. It will fail if the actual value lacks the property 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().

Parameters
Name Type Description
property
String

The property name

Returns
Type Description
Object

The current instance

Example
test.value({prop: 'foobar'}).isEnumerable('prop');

See also

isNotEnumerable(property)


Assert that the actual value has a non-enumerable property. It will fail if the actual value lacks the property 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().

Parameters
Name Type Description
property
String

The property name

Returns
Type Description
Object

The current instance

Example
test
  .value(function() {})
     .isNotEnumerable('call')

  .value(Object.create({}, {prop: {enumerable: 0}}))
    .isNotEnumerable('prop')
;

isFrozen()


Assert that the actual value is frozen with Object.isFrozen.

Returns
Type Description
Object

The current instance

Example
test.value(Object.freeze({})).isFrozen();

isNotFrozen()


Assert that the actual value is not frozen with Object.isFrozen.

Returns
Type Description
Object

The current instance

Example
test.value({}).isNotFrozen();

isInstanceOf(expected)


Assert that the actual value is an instance of expected value.

Uses actual instanceof expected.

Parameters
Name Type Description
expected
Object

Expected instance

Returns
Type Description
Object

The current instance

Example
test.value(new Date()).isInstanceOf(Date);

isNotInstanceOf(expected)


Assert that the actual value is not an instance of expected value.

Uses actual instanceof expected === false.

Parameters
Name Type Description
expected
Object

Expected instance

Returns
Type Description
Object

The current instance

Example
test.value(new Date()).isNotInstanceOf(RegExp);

hasProperty(property, value)


Assert that the actual tested value has property. Optionally assert it equals (===) to value argument.

Takes inherited properties into account. To not do so, see hasOwnProperty().

Parameters
Name Type Argument Description
property
String

The property name

value
mixed
optional 

The property value

Returns
Type Description
Object

The current instance

Example
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 a property. Optionally assert it not equals (!==) to value argument.

Takes inherited properties into account. To not do so, see hasNotOwnProperty().

Parameters
Name Type Argument Description
property
String

The property name

value
mixed
optional 

The property value

Returns
Type Description
Object

The current instance

Example
test
  .value({foo: 'bar'})
    .hasNotProperty('bar')

  .value({foo: 'bar'})
    .hasNotProperty('foo', 'baz')
;

See also

hasOwnProperty(property, value)


Assert that the actual tested value has own property. Optionally assert it equals (===) to value argument.

Does not take inherited properties into account. To do so, see hasProperty().

Parameters
Name Type Argument Description
property
String

The property name

value
mixed
optional 

The property value

Returns
Type Description
Object

The current instance

Example
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 own property. Optionally assert it not equals (!==) to value argument.

Does not take inherited properties into account. To do so, see hasNotProperty().

Parameters
Name Type Argument Description
property
String

The property name

value
mixed
optional 

The property value

Returns
Type Description
Object

The current instance

Example
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 enumerable properties. Pass an array of strings as properties.

Takes inherited properties into account. To not do so, see hasOwnProperties().

Parameters
Name Type Description
properties
Array

An array of expected properties

Returns
Type Description
Object

The current instance

Example
test.value({foo: 'bar', bar: 'huhu', other: 'vroom'})
  .hasProperties(['other', 'bar', 'foo']);

hasNotProperties(properties)


Assert that the actual value has not the enumerable properties. Pass an array of strings as properties.

Takes inherited properties into account. To not do so, see hasNotOwnProperties().

Parameters
Name Type Description
properties
Array

An array of properties

Returns
Type Description
Object

The current instance

Example
test.value({foo: 'bar', bar: 'huhu', other: 'vroom'})
  .hasNotProperties(['other', 'foo']);

hasOwnProperties(properties)


Assert that the actual value has only the expected enumerable properties of its own. Pass an array of strings as properties.

Does not take inherited properties into account. To do so, see hasProperties.

Parameters
Name Type Description
properties
Array

An array of expected properties

Returns
Type Description
Object

The current instance

Example
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 a key. Optionally assert it equals (===) to value argument.

Takes inherited properties into account. To not do so, see hasOwnProperty().

Parameters
Name Type Argument Description
key
String

The key name

value
mixed
optional 

The key value

Returns
Type Description
Object

The current instance

Example
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 a key. Optionally assert it not equals (!==) to value argument.

Takes inherited properties into account. To not do so, see hasNotOwnProperty().

Parameters
Name Type Argument Description
key
String

The key name

value
mixed
optional 

The key value

Returns
Type Description
Object

The current instance

Example
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 enumerable keys. Pass an array of strings as keys.

Takes inherited properties into account. To not do so, see hasOwnProperties().

Parameters
Name Type Description
keys
Array

An array of expected keys

Returns
Type Description
Object

The current instance

Example
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 enumerable keys. Pass an array of strings as keys.

Takes inherited properties into account. To not do so, see hasNotOwnProperties().

Parameters
Name Type Description
keys
Array

An array of keys

Returns
Type Description
Object

The current instance

Example
test.value({foo: 'bar', bar: 'huhu', other: 'vroom'})
      .notHasKeys(['other', 'foo']);

hasValue(expected)


Assert that the actual tested value has expected value.

For strings it checks the text, for arrays it checks elements and for objects the property values. Everything is checked with strict equals (===).

Parameters
Name Type Description
expected
mixed

The expected value

Returns
Type Description
Object

The current instance

Example
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 has expected value.

For strings it checks the text, for arrays it checks elements and for objects the property values. Everything is checked with strict equals (!==).

Parameters
Name Type Description
expected
mixed

The expected value

Returns
Type Description
Object

The current instance

Example
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 several expected values passed in an array of expected values.

Parameters
Name Type Description
expected
Array

An array of expected values

Returns
Type Description
Object

The current instance

Example
test.value([1, 42, 3]).hasValues([42, 3]);

See also

notHasValues(expected)


Assert that the actual tested value not has several expected values passed in an array of expected values.

Parameters
Name Type Description
expected
Array

An array of expected values

Returns
Type Description
Object

The current instance

Example
test.value([1, 42, 3]).notHasValues([4, 2]);

See also

contains(expected)


Assert that the actual value to contain something (===) to expected within depth.

Parameters
Name Type Argument Description
expected
mixed
repeatable 

One or more expected value.

Returns
Type Description
Object

The current instance

Example
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 (!==) to expected within depth.

Parameters
Name Type Argument Description
expected
mixed
repeatable 

One or more expected value.

Returns
Type Description
Object

The current instance

Example
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 the expected 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 (===).

Parameters
Name Type Description
expected
Array

The expected reverse array.

Returns
Type Description
Object

The current instance

Example
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 the expected 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 (===).

Parameters
Name Type Description
expected
Array

The expected reverse array.

Returns
Type Description
Object

The current instance

Example
test
  .value([1, 2, 2, 3])
    .isNotReverseOf([3, 2, 1])
;

See also

startsWith(str)


Assert that the actual value starts with str.

Parameters
Name Type Description
str
String

Expected string value

Returns
Type Description
Object

The current instance

Example
test.value('foobar').startsWith('foo');

notStartsWith(str)


Assert that the actual value not starts with str.

Parameters
Name Type Description
str
String

Expected string value

Returns
Type Description
Object

The current instance

Example
test.value('foobar').notStartsWith('bar');

endsWith(str)


Assert that the actual value ends with str.

Parameters
Name Type Description
str
String

Expected string value

Returns
Type Description
Object

The current instance

Example
test.value('foobar').endsWith('bar');

notEndsWith(str)


Assert that the actual value not ends with str.

Parameters
Name Type Description
str
String

Expected string value

Returns
Type Description
Object

The current instance

Example
test.value('foobar').notEndsWith('foo');

hasHttpStatus(code)


Assert that the actual value has a given HTTP status code.

Parameters
Name Type Description
code
String

Expected code value

Returns
Type Description
Object

The current instance

Example
// 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 status code.

Parameters
Name Type Description
code
String

Expected code value

Returns
Type Description
Object

The current instance

Example
// 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 header field and optional value are present.

Parameters
Name Type Argument Description
field
String

Field name

value
String
Number
optional 

Header value

Returns
Type Description
Object

The current instance

Example
// 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 header field and optional value are not present.

Parameters
Name Type Argument Description
field
String

Field name

value
String
Number
optional 

Header value

Returns
Type Description
Object

The current instance

Example
// 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).

Returns
Type Description
Object

The current instance

Example
// 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).

Returns
Type Description
Object

The current instance

Example
// 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).

Returns
Type Description
Object

The current instance

Example
// 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).

Returns
Type Description
Object

The current instance

Example
// 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();