feat(jsdoc-test-matchers): add toBeInstanceOf matcher

This commit is contained in:
Jeff Williams 2019-10-09 13:05:40 -04:00
parent e5d0725627
commit a912012bba

View File

@ -8,5 +8,27 @@ addMatchers({
},
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;
}
});