A comprehensive matcher library for Jest testing framework providing assertion utilities for test expectations
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Specialized matchers for numeric comparisons and floating-point precision testing. These matchers provide essential tools for mathematical assertions and boundary testing.
Checks if a number is greater than the expected value.
/**
* Checks if number is greater than expected value
* @param expected - Number to compare against
*/
ExpectationObject.toBeGreaterThan(expected: number): void;Usage Examples:
expect(10).toBeGreaterThan(5);
expect(3.5).toBeGreaterThan(3);
expect(-1).toBeGreaterThan(-5);
// Useful for testing ranges and boundaries
const score = calculateScore();
expect(score).toBeGreaterThan(0);
expect(score).toBeGreaterThan(passingScore);Checks if a number is greater than or equal to the expected value.
/**
* Checks if number is greater than or equal to expected value
* @param expected - Number to compare against
*/
ExpectationObject.toBeGreaterThanOrEqual(expected: number): void;Usage Examples:
expect(10).toBeGreaterThanOrEqual(10);
expect(10).toBeGreaterThanOrEqual(5);
expect(0).toBeGreaterThanOrEqual(0);
// Testing minimum values
const userAge = getUserAge();
expect(userAge).toBeGreaterThanOrEqual(18); // legal age requirementChecks if a number is less than the expected value.
/**
* Checks if number is less than expected value
* @param expected - Number to compare against
*/
ExpectationObject.toBeLessThan(expected: number): void;Usage Examples:
expect(5).toBeLessThan(10);
expect(-10).toBeLessThan(-5);
expect(2.99).toBeLessThan(3);
// Testing maximum limits
const responseTime = measureResponseTime();
expect(responseTime).toBeLessThan(1000); // should be under 1 secondChecks if a number is less than or equal to the expected value.
/**
* Checks if number is less than or equal to expected value
* @param expected - Number to compare against
*/
ExpectationObject.toBeLessThanOrEqual(expected: number): void;Usage Examples:
expect(10).toBeLessThanOrEqual(10);
expect(5).toBeLessThanOrEqual(10);
expect(-1).toBeLessThanOrEqual(0);
// Testing upper bounds
const batteryLevel = getBatteryLevel();
expect(batteryLevel).toBeLessThanOrEqual(100); // can't exceed 100%Checks if a floating-point number is close to the expected value within a specified precision.
/**
* Checks if floating point number is close to expected value
* @param expected - Expected number value
* @param precision - Number of decimal places for precision (default: 2)
*/
ExpectationObject.toBeCloseTo(expected: number, precision?: number): void;Usage Examples:
// Default precision (2 decimal places)
expect(0.1 + 0.2).toBeCloseTo(0.3); // handles floating point imprecision
expect(Math.PI).toBeCloseTo(3.14);
// Custom precision
expect(Math.PI).toBeCloseTo(3.14159, 5); // 5 decimal places
expect(1/3).toBeCloseTo(0.333, 3); // 3 decimal places
// Useful for calculations that may have small rounding errors
const result = complexCalculation();
expect(result).toBeCloseTo(expectedValue, 4);Checks if a value is NaN (Not a Number).
/**
* Checks if value is NaN (Not a Number)
*/
ExpectationObject.toBeNaN(): void;Usage Examples:
expect(NaN).toBeNaN();
expect(parseInt('not a number')).toBeNaN();
expect(Math.sqrt(-1)).toBeNaN();
expect(0 / 0).toBeNaN();
// Testing invalid calculations
const result = divide(10, 0);
if (shouldBeInvalid) {
expect(result).toBeNaN();
} else {
expect(result).not.toBeNaN();
}// Testing if a value falls within a range
const temperature = getTemperature();
expect(temperature).toBeGreaterThan(0);
expect(temperature).toBeLessThan(100);
// Or combined
expect(temperature).toBeGreaterThan(0);
expect(temperature).toBeLessThan(100);// Testing edge cases around boundaries
const limit = 100;
expect(getValue()).toBeLessThanOrEqual(limit);
expect(getValue()).toBeGreaterThanOrEqual(0);
// Testing just inside boundaries
expect(99).toBeLessThan(limit);
expect(100).toBeLessThanOrEqual(limit);// Handling currency calculations
const price1 = 19.99;
const price2 = 9.99;
const total = price1 + price2;
expect(total).toBeCloseTo(29.98, 2); // 2 decimal places for currency
// Tax calculations
const tax = calculateTax(100, 0.0825); // 8.25% tax
expect(tax).toBeCloseTo(8.25, 2);All numeric matchers support negation:
expect(5).not.toBeGreaterThan(10);
expect(10).not.toBeLessThan(5);
expect(Math.PI).not.toBeCloseTo(3, 0);
expect(42).not.toBeNaN();All numeric matchers work with promises:
await expect(Promise.resolve(42)).resolves.toBeGreaterThan(40);
await expect(Promise.resolve(3.14159)).resolves.toBeCloseTo(3.14, 2);
await expect(Promise.resolve(parseInt('invalid'))).resolves.toBeNaN();