mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
feat(jsdoc-test-matchers): add toBeInstanceOf matcher
This commit is contained in:
parent
e5d0725627
commit
a912012bba
@ -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;
|
||||
}
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user