2021-09-19 13:20:31 -07:00

35 lines
773 B
JavaScript

const { addMatchers } = require('add-matchers');
require('jasmine-expect');
addMatchers({
toBeError(value) {
return value instanceof Error;
},
toBeErrorOfType(other, value) {
return value instanceof Error && value.name === other;
},
toBeInstanceOf(other, value) {
let otherName;
let valueName;
if (typeof value !== 'object') {
throw new TypeError(`Expected object value, got ${typeof value}`);
}
valueName = value.constructor.name;
// Class name.
if (typeof other === 'string') {
otherName = other;
// Class constructor.
} else if (typeof other === 'function') {
otherName = other.name;
} else {
otherName = other.constructor.name;
}
return valueName === otherName;
},
});