{"record":{"id":"612b79d7d2ac2c0d","repo":"vitest-dev/vitest","slug":"getassertionname-assertion-cannot-be-used-with","errorCode":null,"errorMessage":"${getAssertionName(assertion)} cannot be used with \"not\"","messagePattern":"(.+?) cannot be used with \"not\"","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/integrations/snapshot/chai.ts","lineNumber":78,"sourceCode":"    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\"`)\n  }\n}\n\nexport const SnapshotPlugin: ChaiPlugin = (chai, utils) => {\n  for (const key of ['matchSnapshot', 'toMatchSnapshot']) {\n    utils.addMethod(\n      chai.Assertion.prototype,\n      key,\n      wrapAssertion(utils, key, function (\n        this,\n        propertiesOrHint?: object | string,\n        hint?: string,\n      ) {\n        const result = toMatchSnapshotImpl({\n          assertion: this,\n          received: utils.flag(this, 'object'),\n          ...normalizeArguments(propertiesOrHint, hint),\n        })","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/vitest/src/integrations/snapshot/chai.ts#L60-L96","documentation":"Thrown by `validateAssertion` when a snapshot assertion is chained with `.not` (the Chai negation flag is set). Snapshot matching is an equivalence check against a stored artifact; negating it ('this value does NOT match the stored snapshot') is ambiguous and not supported, so Vitest rejects the combination. The message names the offending assertion.","triggerScenarios":"Writing `expect(value).not.toMatchSnapshot()`, `expect(value).not.toMatchInlineSnapshot()`, or `expect(fn).not.toThrowErrorMatchingSnapshot()`.","commonSituations":"Reaching for `.not` out of habit when asserting a value differs from a snapshot; misunderstanding that snapshots are write-once/compare rather than boolean matches.","solutions":["Drop the `.not` and update the snapshot to the expected value (or assert the specific difference with `toEqual`/`toMatchObject`).","If you need to assert a value is NOT a specific shape, use `expect(value).not.toEqual(unwanted)` with an explicit expected rather than a snapshot.","For inline checks, compare against an explicit literal instead of an inline snapshot."],"exampleFix":"// before\nexpect(result).not.toMatchSnapshot()\n\n// after\nexpect(result).toEqual({ status: 'ok' })","handlingStrategy":"validation","validationCode":"// never chain .not before a snapshot matcher\n// static check: reject 'not.toMatchSnapshot' / 'not.toMatchInlineSnapshot' in review","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never use .not with snapshot matchers.","For 'is not equal to X' assertions, use toEqual with an explicit expected value.","Add an ESLint custom rule or code-review check to forbid .not.toMatchSnapshot."],"tags":["snapshot","negation","chai","api-misuse"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}