avajs/ava · error · AssertionError
The `instanceOf` property of the second argument to `${asser
Error message
The `instanceOf` property of the second argument to `${assertion}` must be a function What it means
validateExpectations guard: the expectations object contained an instanceOf key whose value is not a constructor function (e.g. a string class name or an instance). The input at fault is expectations.instanceOf.
Source
Thrown at lib/assert.js:99
});
}
expectations = {};
} else if (
typeof expectations === 'function'
|| typeof expectations === 'string'
|| expectations instanceof RegExp
|| typeof expectations !== 'object'
|| Array.isArray(expectations)
|| Object.keys(expectations).length === 0
) {
throw new AssertionError(`The second argument to \`${assertion}\` must be an expectation object, \`null\` or \`undefined\``, {
assertion,
formattedDetails: [formatWithLabel('Called with:', expectations)],
});
} else {
if (Object.hasOwn(expectations, 'instanceOf') && typeof expectations.instanceOf !== 'function') {
throw new AssertionError(`The \`instanceOf\` property of the second argument to \`${assertion}\` must be a function`, {
assertion,
formattedDetails: [formatWithLabel('Called with:', expectations)],
});
}
if (
Object.hasOwn(expectations, 'message')
&& typeof expectations.message !== 'string'
&& !(expectations.message instanceof RegExp)
&& !(typeof expectations.message === 'function')
) {
throw new AssertionError(`The \`message\` property of the second argument to \`${assertion}\` must be a string, regular expression or a function`, {
assertion,
formattedDetails: [formatWithLabel('Called with:', expectations)],
});
}
if (Object.hasOwn(expectations, 'name') && typeof expectations.name !== 'string') {View on GitHub (pinned to bbfd946322)
Solutions
- Pass the constructor itself: {instanceOf: TypeError}, not 'TypeError'
- Import the error class you expect and reference it directly
- Remove instanceOf if you meant to match with message or name
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at lib/assert.js:99 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of avajs/ava@bbfd946322 (2026-09-02).
Data as JSON: /api/errors/42370c467716884c.
Report an issue: GitHub.