diff --git a/packages/jsdoc-test-matchers/index.js b/packages/jsdoc-test-matchers/index.js index 8e717531..ab3831a5 100644 --- a/packages/jsdoc-test-matchers/index.js +++ b/packages/jsdoc-test-matchers/index.js @@ -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; } });