avajs/ava · error · AssertionError

The `message` property of the second argument to `${assertio

Error message

The `message` property of the second argument to `${assertion}` must be a string, regular expression or a function

What it means

validateExpectations guard: expectations.message must be a string, RegExp, or function used to match the thrown error's message, but some other type (number, object, boolean, etc.) was given. The input at fault is expectations.message.

Source

Thrown at lib/assert.js:111

		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') {
			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)],
			});
		}

View on GitHub (pinned to bbfd946322)

Solutions

  1. Pass a string for exact comparison or a RegExp for partial matching
  2. Use a function (message) => boolean for custom matching
  3. Coerce numbers/objects to strings before placing them in message
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at lib/assert.js:111 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/2630c2268bc41a0c. Report an issue: GitHub.