{"record":{"id":"ba83fd9e7bc42d3b","repo":"avajs/ava","slug":"the-second-argument-to-assertion-must-be-an-e","errorCode":null,"errorMessage":"The second argument to `${assertion}` must be an expectation object or `undefined`","messagePattern":"The second argument to `(.+?)` must be an expectation object or `undefined`","errorType":"validation","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"lib/assert.js","lineNumber":78,"sourceCode":"\treturn new AssertionError('The assertion message must be a string', {\n\t\tassertion,\n\t\tformattedDetails: [formatWithLabel('Called with:', message)],\n\t});\n}\n\nexport function getAssertionStack(constructorOpt = getAssertionStack) {\n\tconst {stackTraceLimit: limitBefore} = Error;\n\tError.stackTraceLimit = Number.POSITIVE_INFINITY;\n\tconst temporary = {};\n\tError.captureStackTrace(temporary, constructorOpt);\n\tError.stackTraceLimit = limitBefore;\n\treturn temporary.stack;\n}\n\nfunction 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});","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/avajs/ava/blob/bbfd946322fdeca2b547a691d947fb4e18c0c67f/lib/assert.js#L60-L96","documentation":"validateExpectations guard: t.throws/t.throwsAsync was called with an explicit null as its second argument, which is indistinguishable from 'no expectations' — only undefined is accepted for that case. The input at fault is the second (expectations) argument being null.","triggerScenarios":"Thrown at lib/assert.js:78 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Omit the second argument instead of passing null when there are no expectations","Pass undefined explicitly if the call site requires an argument","Pass a real expectations object, e.g. {instanceOf: Error}"],"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"}