These assertions test numeric values, ranges, and mathematical relationships.
👉 See to be a number
Success:
expect(Infinity, 'to be infinite');
expect(-Infinity, 'to be infinite');
Failure:
expect(42, 'to be infinite');
// AssertionError: Expected 42 to be infinite
Negation:
expect(42, 'not to be infinite');
Success:
expect(Infinity, 'to be Infinity');
Failure:
expect(-Infinity, 'to be Infinity');
// AssertionError: Expected -Infinity to be Infinity
Negation:
expect(-Infinity, 'not to be Infinity');
Success:
expect(-Infinity, 'to be -Infinity');
Failure:
expect(Infinity, 'to be -Infinity');
// AssertionError: Expected Infinity to be -Infinity
Negation:
expect(Infinity, 'not to be -Infinity');
Aliases:
to be positive
,to be a positive number
Success:
expect(42, 'to be positive');
expect(3.14, 'to be positive');
Failure:
expect(-5, 'to be positive');
// AssertionError: Expected -5 to be positive
expect(0, 'to be positive');
Negation:
expect(-5, 'not to be positive');
expect(0, 'not to be positive');
Aliases:
to be a positive integer
,to be a positive int
Success:
expect(42, 'to be a positive integer');
expect(1, 'to be a positive integer');
Failure:
expect(3.14, 'to be a positive integer');
// AssertionError: Expected 3.14 to be a positive integer
expect(-5, 'to be a positive integer');
Negation:
expect(3.14, 'not to be a positive integer');
Aliases:
to be negative
,to be a negative number
Success:
expect(-42, 'to be negative');
expect(-3.14, 'to be negative');
Failure:
expect(5, 'to be negative');
// AssertionError: Expected 5 to be negative
expect(0, 'to be negative');
Negation:
expect(5, 'not to be negative');
expect(0, 'not to be negative');
Aliases:
to be a negative integer
,to be a negative int
Success:
expect(-42, 'to be a negative integer');
expect(-1, 'to be a negative integer');
Failure:
expect(-3.14, 'to be a negative integer');
// AssertionError: Expected -3.14 to be a negative integer
expect(5, 'to be a negative integer');
Negation:
expect(-3.14, 'not to be a negative integer');
Success:
expect(NaN, 'to be NaN');
expect(Number.NaN, 'to be NaN');
Failure:
expect(42, 'to be NaN');
// AssertionError: Expected 42 to be NaN
Negation:
expect(42, 'not to be NaN');
Aliases:
to be an integer
,to be a safe integer
,to be an int
,to be a safe int
Success:
expect(42, 'to be an integer');
expect(-17, 'to be an integer');
expect(0, 'to be an integer');
Failure:
expect(3.14, 'to be an integer');
// AssertionError: Expected 3.14 to be an integer
Negation:
expect(3.14, 'not to be an integer');
Success:
expect(10, 'to be greater than', 5);
expect(3.14, 'to be greater than', 3);
Failure:
expect(5, 'to be greater than', 10);
// AssertionError: Expected 5 to be greater than 10
Negation:
expect(5, 'not to be greater than', 10);
Success:
expect(5, 'to be less than', 10);
expect(3, 'to be less than', 3.14);
Failure:
expect(10, 'to be less than', 5);
// AssertionError: Expected 10 to be less than 5
Negation:
expect(10, 'not to be less than', 5);
Aliases:
to be greater than or equal to <number>
,to be at least <number>
Success:
expect(10, 'to be greater than or equal to', 10);
expect(15, 'to be at least', 10);
Failure:
expect(5, 'to be greater than or equal to', 10);
// AssertionError: Expected 5 to be greater than or equal to 10
Negation:
expect(5, 'not to be greater than or equal to', 10);
Aliases:
to be less than or equal to <number>
,to be at most <number>
Success:
expect(10, 'to be less than or equal to', 10);
expect(5, 'to be at most', 10);
Failure:
expect(15, 'to be less than or equal to', 10);
// AssertionError: Expected 15 to be less than or equal to 10
Negation:
expect(15, 'not to be less than or equal to', 10);
Aliases:
to be within <number> and <number>
,to be between <number> and <number>
Success:
expect(5, 'to be within', 1, 10);
expect(7.5, 'to be between', 7, 8);
Failure:
expect(15, 'to be within', 1, 10);
// AssertionError: Expected 15 to be within 1 and 10
Negation:
expect(15, 'not to be within', 1, 10);
Success:
expect(1.0, 'to be close to', 1.1, 0.2);
expect(3.14159, 'to be close to', 3.14, 0.01);
Failure:
expect(1.0, 'to be close to', 2.0, 0.5);
// AssertionError: Expected 1.0 to be close to 2.0 within 0.5
Negation:
expect(1.0, 'not to be close to', 2.0, 0.5);