{"record":{"id":"0cb180b6b231a444","repo":"avajs/ava","slug":"message-test-failed-via-t-fail","errorCode":null,"errorMessage":"message ?? 'Test failed via `t.fail()`'","messagePattern":"message \\?\\? 'Test failed via `t\\.fail\\(\\)`'","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"lib/assert.js","lineNumber":288,"sourceCode":"\t} = {}) {\n\t\tconst withSkip = assertionFn => {\n\t\t\tassertionFn.skip = skip;\n\t\t\treturn assertionFn;\n\t\t};\n\n\t\tconst assertMessage = (message, assertion) => {\n\t\t\tconst result = checkAssertionMessage(message, assertion);\n\t\t\tif (result !== true) {\n\t\t\t\tthrow fail(result);\n\t\t\t}\n\t\t};\n\n\t\tthis.pass = withSkip(() => pass());\n\n\t\tthis.fail = withSkip(message => {\n\t\t\tassertMessage(message, 't.fail()');\n\n\t\t\tthrow fail(new AssertionError(message ?? 'Test failed via `t.fail()`', {\n\t\t\t\tassertion: 't.fail()',\n\t\t\t}));\n\t\t});\n\n\t\tthis.is = withSkip((actual, expected, message) => {\n\t\t\tassertMessage(message, 't.is()');\n\n\t\t\tif (Object.is(actual, expected)) {\n\t\t\t\treturn pass();\n\t\t\t}\n\n\t\t\tconst result = concordance.compare(actual, expected, concordanceOptions);\n\t\t\tconst actualDescriptor = result.actual ?? concordance.describe(actual, concordanceOptions);\n\t\t\tconst expectedDescriptor = result.expected ?? concordance.describe(expected, concordanceOptions);\n\n\t\t\tif (result.pass) {\n\t\t\t\tthrow fail(new AssertionError(message, {\n\t\t\t\t\tassertion: 't.is()',","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/avajs/ava/blob/bbfd946322fdeca2b547a691d947fb4e18c0c67f/lib/assert.js#L270-L306","documentation":"This is the t.fail() assertion failure itself. When t.fail(message) is called, AVA throws an AssertionError whose message is the caller-provided message, or the default 'Test failed via `t.fail()`' when no message is given (lib/assert.js:288). t.fail unconditionally fails the test — the throw is the intended behavior, not a bug.","triggerScenarios":"Explicitly calling t.fail() or t.fail('my message') anywhere inside a test or hook body; also reached when custom validation code calls t.fail to mark an unexpected branch.","commonSituations":"See trigger scenarios.","solutions":["Replace t.fail() with real assertions once the test is implemented.","If the failure is unexpected, find the call site — the AssertionError is deliberately thrown there; the assertion name 't.fail()' appears in the error's assertion property.","Use t.pass() or skip the test (test.todo / test.skip) for intentionally unimplemented tests."],"exampleFix":"// before\ntest('greets', t => {\n  t.fail(); // TODO\n});\n\n// after\ntest('greets', async t => {\n  const out = greet();\n  t.is(out, 'hello');\n});","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// t.fail throws by design; guard intentional-failure tests:\ntry {\n  t.fail('should not run');\n} catch (e) {\n  // expected: e.assertion === 't.fail()'\n}","preventionTips":["Replace t.fail() placeholders with real assertions before merging.","Use test.todo() or test.skip() for unimplemented tests instead of t.fail().","Search CI logs for t.fail() call sites when the failure is unexpected."],"tags":["ava","assertions","t-fail","test-failure"],"backgroundTag":"assertion-failed","analyzedSha":"bbfd946322fdeca2b547a691d947fb4e18c0c67f","analyzedAt":"2026-09-02T01:24:43.834Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}