@stackbit/utils
Version:
Stackbit utilities
25 lines (21 loc) • 794 B
JavaScript
const { expect } = require('@jest/globals');
function toBeWithinRange(actual, floor, ceiling) {
if (typeof actual !== 'number' || typeof floor !== 'number' || typeof ceiling !== 'number') {
throw new Error('These must be of type number!');
}
const pass = actual >= floor && actual <= ceiling;
if (pass) {
return {
message: () => `expected ${this.utils.printReceived(actual)} not to be within range ${this.utils.printExpected(`${floor} - ${ceiling}`)}`,
pass: true
};
} else {
return {
message: () => `expected ${this.utils.printReceived(actual)} to be within range ${this.utils.printExpected(`${floor} - ${ceiling}`)}`,
pass: false
};
}
}
expect.extend({
toBeWithinRange
});