{"record":{"id":"87cc8f99fc6db3d6","repo":"vitest-dev/vitest","slug":"assertion-name-is-not-set-this-is-a-bug-in-vitest","errorCode":null,"errorMessage":"Assertion name is not set. This is a bug in Vitest. Please, open a new issue with reproduction.","messagePattern":"Assertion name is not set\\. This is a bug in Vitest\\. Please, open a new issue with reproduction\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/integrations/snapshot/chai.ts","lineNumber":60,"sourceCode":"  catch (e) {\n    return e\n  }\n\n  throw new Error('snapshot function didn\\'t throw')\n}\n\nfunction getTestNames(test: Test) {\n  return {\n    filepath: test.file.filepath,\n    name: getNames(test).slice(1).join(' > '),\n    testId: test.id,\n  }\n}\n\nfunction getAssertionName(assertion: Chai.Assertion): string {\n  const name = chai.util.flag(assertion, '_name') as string | undefined\n  if (!name) {\n    throw new Error('Assertion name is not set. This is a bug in Vitest. Please, open a new issue with reproduction.')\n  }\n  return name\n}\n\nfunction getTest(obj: Chai.Assertion) {\n  const test = chai.util.flag(obj, 'vitest-test') as Test | undefined\n  if (!test) {\n    throw new Error(`'${getAssertionName(obj)}' cannot be used without test context`)\n  }\n  if (test.fails) {\n    throw new TestSyntaxError(`'${getAssertionName(obj)}' cannot be used with 'test.fails'`)\n  }\n  return test\n}\n\nfunction validateAssertion(assertion: Chai.Assertion): void {\n  if (chai.util.flag(assertion, 'negate')) {\n    throw new Error(`${getAssertionName(assertion)} cannot be used with \"not\"`)","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/vitest/src/integrations/snapshot/chai.ts#L42-L78","documentation":"Thrown by `getAssertionName` when a snapshot assertion is invoked but the internal Chai `_name` flag was never set. Vitest relies on `wrapAssertion`/explicit flag setting to record the assertion's name (e.g. `toMatchSnapshot`); an absent name indicates the assertion was registered incorrectly — an internal Vitest bug, not a user error. The message explicitly asks the user to file a bug with a reproduction.","triggerScenarios":"Effectively unreachable through the public API. Could only occur if a snapshot assertion method was added to the Assertion prototype without going through `wrapAssertion` or without setting `_name`, or if the flag was stripped by a chai utility.","commonSituations":"Should not occur for end users. If seen after upgrading Vitest, suspect an internal regression, a custom chai plugin clobbering flags, or HMR/module duplication.","solutions":["Report a bug to Vitest with a minimal reproduction (the message requests this).","Check for custom chai plugins or third-party assertion extensions that may clear flags.","Ensure only one copy of Vitest is installed (dedupe) to avoid prototype double-registration."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  expect(value).toMatchSnapshot()\n} catch (e) {\n  if (e instanceof Error && /Assertion name is not set/.test(e.message)) {\n    // internal bug: report to Vitest with a reproduction\n  }\n  throw e\n}","preventionTips":["Use a single Vitest version across the workspace (dedupe).","Avoid custom chai plugins that clear Chai flags.","Report internal bugs upstream rather than working around them."],"tags":["snapshot","internal","bug","unreachable","chai"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}