number

Number asserter.

Assert that the actual value is a number (using .isNumber() assertion). The number() asserter provides adapted assertions for works on a number.

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

Example

test.number(actual);

Methods

is(expected)


Assert actual number equality.

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

  • Number value are compared to number literals.

Parameters
Name Type Description
expected
mixed

Expected number

Returns
Type Description
Object

The current instance

Example
test.number(2).is(2);

See also

isNot(expected)


Assert actual number to the negative equality.

Also handles circular and self-referential objects.

Parameters
Name Type Description
expected
mixed

Expected value

Returns
Type Description
Object

The current instance

Example
test
  .number(2)
    .isNot(3)
    .isNot('2')
    .isNot(2.1)
;

See also

isIdenticalTo(expected)


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

Parameters
Name Type Description
expected
mixed

Expected value

Returns
Type Description
Object

The current instance

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

See also

isNotIdenticalTo(expected)


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

Parameters
Name Type Description
expected
mixed

Expected number

Returns
Type Description
Object

The current instance

Example
test
  .number(2)
    .isNotIdenticalTo(3)
    .isNotIdenticalTo('2')
    .isNotIdenticalTo(2.1)
    .isNotIdenticalTo(0.2)
;

See also

isEqualTo(expected)


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

Parameters
Name Type Description
expected
mixed

Expected number

Returns
Type Description
Object

The current instance

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

See also

isNotEqualTo(expected)


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

Parameters
Name Type Description
expected
mixed

Expected number

Returns
Type Description
Object

The current instance

Example
test.number(2).isNotEqualTo(3);

See also

match(expected)


Assert actual number 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

  // Assert with a RegExp
  .number(2014).match(/20+[1-4]/)

  // Assert with a number converted to RegExp
  .number(2014).match(201)

  // Assert with a function
  .number(2014).match(function(it){
    return it === 2014;
  })
;

See also

notMatch(expected)


Assert actual number 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

  // Assert with a RegExp
  .number(2014)
    .notMatch(/20+[5-6]/)
    .notMatch(/[a-z]/)

  // Assert with a number converted to RegExp
  .number(10)
    .notMatch(8)

  // Assert with a function
  .number(10)
    .notMatch(function(it){
      return it === 42;
    })
;

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

  // Assert with a RegExp
  .number(2014).isValid(/20+[1-4]/)

  // Assert with a number converted to RegExp
  .number(2014).isValid(201)

  // Assert with a function
  .number(2014).isValid(function(it){
    return it === 2014;
  })
;

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

  // Assert with a RegExp
  .number(2014)
    .isNotValid(/20+[5-6]/)
    .isNotValid(/[a-z]/)

  // Assert with a number converted to RegExp
  .number(10)
    .isNotValid(8)

  // Assert with a function
  .number(10)
    .isNotValid(function(it){
      return it === 42;
    })
;

See also

matchEach(expected)


Assert actual number 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
  .number(2014)
    .matchEach([2, 4, 1, 0])
    .matchEach([2014, function(it){
      return it === 2014;
    }])
;

See also

notMatchEach(expected)


Assert actual number 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
  .number(2014)
    .notMatchEach([3, 200])
    .notMatchEach([2012, function(it){
      return it !== 2014;
    }])
;

See also

isBetween(begin, end)


Assert that the actual number 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
  .number(2)
    .isBetween(2, 4)

  .number(3)
    .isBetween(2, 4)

  .number(4)
    .isBetween(2, 4)
;

See also

isNotBetween(begin, end)


Assert that the actual number 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
  .number(1)
    .isNotBetween(2, 4)

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

See also

isBefore(expected)


Alias of isLessThan().

Assert that the actual number is before the expected value.

Parameters
Name Type Description
expected
mixed

Expected value

Returns
Type Description
Object

The current instance

Example
test.number(1).isBefore(2);

See also

isAfter(expected)


Alias of isGreaterThan().

Assert that the actual number is after the expected value.

Parameters
Name Type Description
expected
mixed

Expected value

Returns
Type Description
Object

The current instance

Example
test.number(2).isAfter(1);

See also

isLessThan(expected)


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

Parameters
Name Type Description
expected
mixed

Expected value

Returns
Type Description
Object

The current instance

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

See also

isGreaterThan(expected)


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

Parameters
Name Type Description
expected
mixed

Expected value

Returns
Type Description
Object

The current instance

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

See also

isApprox(num, delta)


Assert that the actual number (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.number(99.98).isApprox(100, 0.02);

See also

isInfinite()


Assert that the actual number is infinite.

Returns
Type Description
Object

The current instance

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

See also

isNotInfinite()


Assert that the actual number is not infinite.

Returns
Type Description
Object

The current instance

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

See also

isNaN()


Assert that the actual number is NaN.

Returns
Type Description
Object

The current instance

Example
test.number(0/0).isNaN();
test.number(parseInt('foo', 10)).isNaN();
test.number(NaN).isNaN();

See also

isNotNaN()


Assert that the actual number is not NaN.

Returns
Type Description
Object

The current instance

Example
test.number(0).isNotNaN();

See also