{"record":{"id":"ea4211b9a86d7a75","repo":"denoland/deno","slug":"err-assertion","errorCode":"ERR_ASSERTION","errorMessage":"${actual} ${operator} ${expected}","messagePattern":"\\$\\{actual\\} \\$\\{operator\\} \\$\\{expected\\}","errorType":"error_code","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/assert.ts","lineNumber":130,"sourceCode":"Assert.prototype.deepStrictEqual = deepStrictEqual;\nAssert.prototype.notDeepStrictEqual = notDeepStrictEqual;\nAssert.prototype.strictEqual = strictEqual;\nAssert.prototype.notStrictEqual = notStrictEqual;\nAssert.prototype.partialDeepStrictEqual = partialDeepStrictEqual;\nAssert.prototype.throws = throws;\nAssert.prototype.rejects = rejects;\nAssert.prototype.doesNotThrow = doesNotThrow;\nAssert.prototype.doesNotReject = doesNotReject;\nAssert.prototype.ifError = ifError;\nAssert.prototype.match = match;\nAssert.prototype.doesNotMatch = doesNotMatch;\n\nfunction innerFail(obj) {\n  if (ObjectPrototypeIsPrototypeOf(ErrorPrototype, obj.message)) {\n    throw obj.message;\n  }\n\n  throw new AssertionError({\n    actual: obj.actual,\n    expected: obj.expected,\n    message: obj.message,\n    operator: obj.operator,\n    stackStartFn: obj.stackStartFn,\n    diff: obj.diff,\n  });\n}\n\nfunction assert(...args) {\n  innerOk(ok, args.length, ...new SafeArrayIterator(args));\n}\nconst ok = assert;\n\nclass Comparison {\n  constructor(obj, keys, actual) {\n    for (const key of new SafeArrayIterator(keys)) {\n      if (ReflectHas(obj, key)) {","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/ext/node/polyfills/assert.ts#L112-L148","documentation":"innerFail is the terminal branch of node:assert when a comparison fails (ext/node/polyfills/assert.ts:130): if the caller supplied an Error object as the message, that error is rethrown as-is; otherwise it throws an AssertionError built from { actual, expected, message, operator, stackStartFn, diff }. The '${actual} ${operator} ${expected}' rendering is the AssertionError's generated message format, so this entry fires on every failed assertion that reaches innerFail (e.g. assert.throws mismatches routed through compareExceptionKey).","triggerScenarios":"assert.strictEqual(1, 2); assert.throws(fn, { code: 'X' }) where fn threw no matching property; assert(fn, customMessageNotProvided); any failed ok/equals family assertion in strict mode routed via innerOk -> innerFail.","commonSituations":"Ordinary test failures — regressions where the value under test changed; overly loose expected objects in assert.throws that mismatch a property; NaN comparisons failing strict equality; async timing changing observed state between runs.","solutions":["Inspect the AssertionError's actual/expected fields (or the diff) to see the divergence, then fix the code or the expectation","In assert.throws validation objects, list only properties that must match (e.g. { name: 'TypeError', message: /boom/ }) instead of deep-equal whole errors","Add assert.fail('why') with explicit messages at branch points so failures surface intent, not just values"],"exampleFix":"// before\nassert.throws(() => parse('nope'), { message: 'exactly this' }); // message differs\n\n// after\nassert.throws(() => parse('nope'), { name: 'SyntaxError', message: /nope/ });","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { assert.strictEqual(actual, expected, 'context: why these must match'); } catch (e) { if (e.code === 'ERR_ASSERTION') { /* inspect e.actual/e.expected, fix code or expectation */ throw e; } throw e; }","preventionTips":["Give assertions message arguments describing intent","Match on selected properties (name/message regex) rather than whole error objects"],"tags":["assert","testing","assertion-failure","node-compat"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}