2020-04-26 18:22:09 +00:00
|
|
|
expect.extend({
|
2020-04-27 23:43:15 +00:00
|
|
|
toBeOfType(received, expectedType) {
|
|
|
|
|
const type = typeof received;
|
|
|
|
|
|
|
|
|
|
const pass = type === expectedType;
|
|
|
|
|
const message = () => `
|
|
|
|
|
Expected value to be of type ${this.utils.printExpected(expectedType)},
|
|
|
|
|
but received ${this.utils.printReceived(type)}`;
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
message,
|
|
|
|
|
pass,
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
|
2020-04-26 18:22:09 +00:00
|
|
|
toBeEitherAFunctionOrAnObject(received) {
|
|
|
|
|
const type = typeof received;
|
|
|
|
|
|
|
|
|
|
const pass = ['object', 'function'].includes(type);
|
2020-04-27 23:43:15 +00:00
|
|
|
const message = () => `Expected a ${this.utils.printExpected('function')}
|
|
|
|
|
or an ${this.utils.printExpected('object')},
|
|
|
|
|
but received ${type}`;
|
2020-04-26 18:22:09 +00:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
message,
|
|
|
|
|
pass,
|
|
|
|
|
};
|
|
|
|
|
},
|
2020-05-01 18:19:25 +00:00
|
|
|
|
|
|
|
|
toBeParsableToANumber(received) {
|
|
|
|
|
let pass = false;
|
|
|
|
|
let errorMessage = '';
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
Number.parseInt(received, 10);
|
|
|
|
|
pass = true;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
errorMessage = error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const message = () => `Expected ${this.utils.printExpected(received)} to be parsable as a number
|
|
|
|
|
, but received error: ${this.utils.printReceived(errorMessage)}.`;
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
message,
|
|
|
|
|
pass,
|
|
|
|
|
};
|
|
|
|
|
},
|
2020-04-26 18:22:09 +00:00
|
|
|
});
|