date

Date asserter.

Assert that the actual value is an instance of Date (using .isDate() assertion). The date() asserter provides adapted assertions for works on a Date instance.

See also the spec of "date" asserter for more examples.

Example

test.date(actual);

Methods

is(expected)


Assert actual Date equality by content and if possible, recursively.

Also handles circular and self-referential objects.

For most parts it asserts strict equality (===), but:

  • Date objects are compared by their value.
  • 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
var date = new Date('2010, 5, 20');

test.date(date).is(new Date('2010, 5, 20'));

See also

isNot(expected)


Assert actual Date to the negative equality by content and if possible, recursively.

Also handles circular and self-referential objects.

For most parts it asserts strict (!==), but:

  • Date objects are compared by their value.
  • 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
var date = new Date('2010, 5, 20');

test.date(date).isNot(new Date('2012, 02, 28'));

See also

isIdenticalTo(expected)


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

Parameters
Name Type Description
expected
mixed

Expected date

Returns
Type Description
Object

The current instance

Example
var date = new Date('2010, 5, 20');
var ref = date;

test.date(ref).isIdenticalTo(date);

See also

isNotIdenticalTo(expected)


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

Parameters
Name Type Description
expected
mixed

Expected date

Returns
Type Description
Object

The current instance

Example
var date = new Date('2010, 5, 20');

test.date(date).isNotIdenticalTo(new Date('2010, 5, 20'));

See also

isEqualTo(expected)


Assert that the actual Date is equal to (==) the expected date.

Parameters
Name Type Description
expected
mixed

Expected date

Returns
Type Description
Object

The current instance

Example
var date = new Date('2010, 5, 20');
var ref = date;

test.date(ref).isEqualTo(date);

See also

isNotEqualTo(expected)


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

Parameters
Name Type Description
expected
mixed

Expected date

Returns
Type Description
Object

The current instance

Example
var date = new Date('2010, 5, 20');

test.date(new Date('2010, 5, 20')).isNotEqualTo(date);

See also

match(expected)


Assert actual Date to match the expected value.

Parameters
Name Type Description
expected
String
Number
RegExp
function

Expected matches

Returns
Type Description
Object

The current instance

Example
test.date(new Date('2010, 5, 20')).match(/2010/);

See also

notMatch(expected)


Assert actual Date 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.date(new Date('2010, 5, 20')).notMatch(/2012/);

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.date(new Date('2010, 5, 20')).isValid(/2010/);

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.date(new Date('2010, 5, 20')).isNotValid(/2012/);

See also

isBetween(begin, end)


Assert that the actual Date 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.date(new Date('2010, 5, 20'))
  .isBetween(new Date('1982, 02, 17'), new Date('2012, 02, 28'));

See also

isNotBetween(begin, end)


Assert that the actual Date 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.date(new Date('2010, 5, 20'))
  .isNotBetween(new Date('2011, 02, 17'), new Date('2012, 02, 28'));

See also

isBefore(expected)


Assert that the actual Date is before the expected value.

Parameters
Name Type Description
expected
mixed

Expected value

Returns
Type Description
Object

The current instance

Example
test.date(new Date(2010, 5, 20)).isBefore(new Date(2012, 2, 28));

See also

isAfter(expected)


Assert that the actual Date is after the expected value.

Parameters
Name Type Description
expected
mixed

Expected value

Returns
Type Description
Object

The current instance

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

See also