{"record":{"id":"ca614866309fa32a","repo":"avajs/ava","slug":"the-second-argument-to-assertion-contains-une","errorCode":null,"errorMessage":"The second argument to `${assertion}` contains unexpected properties","messagePattern":"The second argument to `(.+?)` contains unexpected properties","errorType":"validation","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"lib/assert.js","lineNumber":150,"sourceCode":"\t\t\tthrow new AssertionError(`The \\`any\\` property of the second argument to \\`${assertion}\\` must be a boolean`, {\n\t\t\t\tassertion,\n\t\t\t\tformattedDetails: [formatWithLabel('Called with:', expectations)],\n\t\t\t});\n\t\t}\n\n\t\tfor (const key of Object.keys(expectations)) {\n\t\t\tswitch (key) {\n\t\t\t\tcase 'instanceOf':\n\t\t\t\tcase 'is':\n\t\t\t\tcase 'message':\n\t\t\t\tcase 'name':\n\t\t\t\tcase 'code':\n\t\t\t\tcase 'any': {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tdefault: {\n\t\t\t\t\tthrow new AssertionError(`The second argument to \\`${assertion}\\` contains unexpected properties`, {\n\t\t\t\t\t\tassertion,\n\t\t\t\t\t\tformattedDetails: [formatWithLabel('Called with:', expectations)],\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn expectations;\n}\n\n// Note: this function *must* throw exceptions, since it can be used\n// as part of a pending assertion for promises.\nfunction assertExpectations({actual, expectations, message, prefix, assertion, assertionStack}) {\n\tconst allowThrowAnything = Object.hasOwn(expectations, 'any') && expectations.any;\n\tif (!isNativeError(actual) && !allowThrowAnything) {\n\t\tthrow new AssertionError(message, {\n\t\t\tassertion,","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/avajs/ava/blob/bbfd946322fdeca2b547a691d947fb4e18c0c67f/lib/assert.js#L132-L168","documentation":"Thrown by validateExpectations in lib/assert.js:150 when the expectation object passed as the second argument to a throws assertion contains a key that is not one of the allowed properties: instanceOf, is, message, name, code, any. This catches typos like `mesage` or `instenceOf` that would otherwise be silently ignored and make the assertion weaker than intended.","triggerScenarios":"Calling t.throws(fn, {mesage: 'x'}), t.throws(fn, {type: 'Error'}), t.throwsAsync(p, {code: 'ERR', foo: 1}) — any expectation key outside the allowed set hits the switch's default branch.","commonSituations":"Typos in expectation keys (most common: `mesage`, `instanceOf` vs `instanceof`); reusing options from other assertion libraries (e.g. Chai's `.throw(Error, /msg/, props)` style); spreading extra runtime data into the expectations object; renaming library APIs across versions.","solutions":["Remove the unexpected key, or fix its spelling to one of: instanceOf, is, message, name, code, any.","If you intended to assert extra properties on the error, assert them separately after capturing the thrown value (e.g. `const err = t.throws(...)` then check `err.code`).","Check the library docs / types for the exact expectation object shape for the version you are using."],"exampleFix":"// before\nt.throws(fn, { mesage: 'boom' });\n\n// after\nt.throws(fn, { message: 'boom' });","handlingStrategy":"validation","validationCode":"const ALLOWED = new Set(['instanceOf', 'is', 'message', 'name', 'code', 'any']);\nfunction assertKnownKeys(expectations) {\n  for (const key of Object.keys(expectations ?? {})) {\n    if (!ALLOWED.has(key)) throw new TypeError(`Unknown expectation key: ${key}`);\n  }\n}","typeGuard":"function isExpectationObject(e) {\n  const allowed = ['instanceOf', 'is', 'message', 'name', 'code', 'any'];\n  return e != null && typeof e === 'object' && !Array.isArray(e) &&\n    Object.keys(e).every(k => allowed.includes(k));\n}","tryCatchPattern":"try {\n  t.throws(fn, expectations);\n} catch (error) {\n  if (error.name === 'AssertionError' && /unexpected properties/.test(error.message)) {\n    console.warn('Bad expectation keys:', Object.keys(expectations));\n  }\n  throw error;\n}","preventionTips":["Memorize the allowed keys: instanceOf, is, message, name, code, any.","Don't spread arbitrary objects into the expectations argument.","Use the typed assertion API (TypeScript definitions) to catch typos at compile time.","Check `instanceOf` spelling — it is not `instanceof` in the expectations object."],"tags":["assertion","improper-usage","typo","unexpected-property","ava"],"backgroundTag":"invalid-assertion-options","analyzedSha":"bbfd946322fdeca2b547a691d947fb4e18c0c67f","analyzedAt":"2026-09-02T01:24:43.834Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}