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:
{unknown} to be positive {unknown} 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:
{unknown} to be a positive integer {unknown} 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:
{unknown} to be negative {unknown} 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:
{unknown} to be a negative integer {unknown} 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:
{unknown} to be an integer {unknown} to be a safe integer {unknown} to be an int {unknown} 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);
âī¸ Aliases:
{unknown} to be less than {number} {unknown} to be lt {number}
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:
{unknown} to be greater than or equal to {number} {unknown} to be at least {number} {unknown} to be gte {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:
{unknown} to be less than or equal to {number} {unknown} to be at most {number} {unknown} to be lte {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:
{number} to be within {number} and {number} {number} to be between {number} and {number}
âšī¸ This assertion is inclusive of the boundary values.
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);
âšī¸ The first number is the subject, the second number is the target, and the third number is the tolerance.
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);