{"record":{"id":"c76c6ed95147e0f7","repo":"avajs/ava","slug":"the-second-argument-to-assertion-must-be-an-e-c76c6e","errorCode":null,"errorMessage":"The second argument to `${assertion}` must be an expectation object, `null` or `undefined`","messagePattern":"The second argument to `(.+?)` must be an expectation object, `null` or `undefined`","errorType":"validation","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"lib/assert.js","lineNumber":93,"sourceCode":"function validateExpectations(assertion, expectations, numberArgs) { // eslint-disable-line complexity\n\tif (numberArgs === 1 || expectations === null || expectations === undefined) {\n\t\tif (expectations === null) {\n\t\t\tthrow new AssertionError(`The second argument to \\`${assertion}\\` must be an expectation object or \\`undefined\\``, {\n\t\t\t\tassertion,\n\t\t\t\tformattedDetails: [formatWithLabel('Called with:', expectations)],\n\t\t\t});\n\t\t}\n\n\t\texpectations = {};\n\t} else if (\n\t\ttypeof expectations === 'function'\n\t\t|| typeof expectations === 'string'\n\t\t|| expectations instanceof RegExp\n\t\t|| typeof expectations !== 'object'\n\t\t|| Array.isArray(expectations)\n\t\t|| Object.keys(expectations).length === 0\n\t) {\n\t\tthrow new AssertionError(`The second argument to \\`${assertion}\\` must be an expectation object, \\`null\\` or \\`undefined\\``, {\n\t\t\tassertion,\n\t\t\tformattedDetails: [formatWithLabel('Called with:', expectations)],\n\t\t});\n\t} else {\n\t\tif (Object.hasOwn(expectations, 'instanceOf') && typeof expectations.instanceOf !== 'function') {\n\t\t\tthrow new AssertionError(`The \\`instanceOf\\` property of the second argument to \\`${assertion}\\` must be a function`, {\n\t\t\t\tassertion,\n\t\t\t\tformattedDetails: [formatWithLabel('Called with:', expectations)],\n\t\t\t});\n\t\t}\n\n\t\tif (\n\t\t\tObject.hasOwn(expectations, 'message')\n\t\t\t&& typeof expectations.message !== 'string'\n\t\t\t&& !(expectations.message instanceof RegExp)\n\t\t\t&& !(typeof expectations.message === 'function')\n\t\t) {\n\t\t\tthrow new AssertionError(`The \\`message\\` property of the second argument to \\`${assertion}\\` must be a string, regular expression or a function`, {","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/avajs/ava/blob/bbfd946322fdeca2b547a691d947fb4e18c0c67f/lib/assert.js#L75-L111","documentation":"validateExpectations guard: the second argument to the assertion was provided, is not null/undefined, but is not a valid expectations object — it is a function, string, RegExp, non-object, array, or an object with no keys. The input at fault is the expectations argument of throws-style assertions.","triggerScenarios":"Thrown at lib/assert.js:93 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Wrap the expectation in an object: {message: '...'} rather than passing a bare string/RegExp","Include at least one known key (instanceOf, message, name, code, is, or anyOf)","Do not pass arrays or functions as the expectations argument"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"bbfd946322fdeca2b547a691d947fb4e18c0c67f","analyzedAt":"2026-09-02T01:24:43.834Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}