avajs/ava · error · AssertionError
The `name` property of the second argument to `${assertion}`
Error message
The `name` property of the second argument to `${assertion}` must be a string What it means
This is an input-validation failure inside validateExpectations, the guard that checks the expectations object passed as the second argument to assertion helpers like t.throws() or t.notThrows(). It fires when expectations has a `name` key whose value is not a string (e.g. a number, object, or undefined), so the assertion cannot match it against an error's name. The assertion never runs; it is rejected up front as a misuse of the API, not as a failed assertion. Fix by passing expectations.name as a string.
Source
Thrown at lib/assert.js:118
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') {
throw new AssertionError(`The \`name\` property of the second argument to \`${assertion}\` must be a string`, {
assertion,
formattedDetails: [formatWithLabel('Called with:', expectations)],
});
}
if (Object.hasOwn(expectations, 'code') && typeof expectations.code !== 'string' && typeof expectations.code !== 'number') {
throw new AssertionError(`The \`code\` property of the second argument to \`${assertion}\` must be a string or number`, {
assertion,
formattedDetails: [formatWithLabel('Called with:', expectations)],
});
}
if (Object.hasOwn(expectations, 'any') && typeof expectations.any !== 'boolean') {
throw new AssertionError(`The \`any\` property of the second argument to \`${assertion}\` must be a boolean`, {
assertion,
formattedDetails: [formatWithLabel('Called with:', expectations)],
});
}View on GitHub (pinned to bbfd946322)
Solutions
- Pass the name as a string, e.g. {name: 'RangeError'}
- Read err.name from a sample error to get the exact string
- Remove the name key if you meant to check the constructor via instanceOf
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at lib/assert.js:118 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/323b1fe31c5c8e2f.
Report an issue: GitHub.