{"id":"6542aacf907a7b9e","repo":"jestjs/jest","slug":"matcherhintfromconfig-snapshot-matchers-c","errorCode":null,"errorMessage":"${matcherHintFromConfig(...)}\n\nSnapshot matchers cannot be used with not","messagePattern":"(.+?)\n\nSnapshot matchers cannot be used with not","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/jest-snapshot/src/index.ts","lineNumber":295,"sourceCode":"const _toMatchSnapshot = (config: MatchSnapshotConfig) => {\n  const {context, hint, inlineSnapshot, isInline, matcherName, properties} =\n    config;\n  let {received} = config;\n\n  /** If a test was ran with `test.failing`. Passed by Jest Circus. */\n  const {testFailing = false} = context;\n\n  if (!testFailing && context.dontThrow) {\n    // Suppress errors while running tests\n    context.dontThrow();\n  }\n\n  const {currentConcurrentTestName, isNot, snapshotState} = context;\n  const currentTestName =\n    currentConcurrentTestName?.() ?? context.currentTestName;\n\n  if (isNot) {\n    throw new Error(\n      matcherErrorMessage(\n        matcherHintFromConfig(config, false),\n        NOT_SNAPSHOT_MATCHERS,\n      ),\n    );\n  }\n\n  if (snapshotState == null) {\n    // Because the state is the problem, this is not a matcher error.\n    // Call generic stringify from jest-matcher-utils package\n    // because uninitialized snapshot state does not need snapshot serializers.\n    throw new Error(\n      `${matcherHintFromConfig(config, false)}\\n\\n` +\n        'Snapshot state must be initialized' +\n        `\\n\\n${printWithType('Snapshot state', snapshotState, stringify)}`,\n    );\n  }\n","sourceCodeStart":277,"sourceCodeEnd":313,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-snapshot/src/index.ts#L277-L313","documentation":"Thrown by `_toMatchSnapshot` (index.ts:294-301) when a snapshot matcher is combined with `.not`. Snapshots are equality checks against a stored baseline; negated snapshot assertions are meaningless (`expect(x).not.toMatchSnapshot()` would pass on any change including the desired one), so Jest rejects them outright.","triggerScenarios":"`expect(x).not.toMatchSnapshot()`, `expect(fn).not.toThrowErrorMatchingSnapshot()`, `expect(x).not.toMatchInlineSnapshot()`.","commonSituations":"Copy-pasting a negated expect template. Misunderstanding snapshot semantics — wanting 'assert this is not yet snapshotted'.","solutions":["Remove `.not`: `expect(x).toMatchSnapshot()`.","If you need to assert that a value differs from a known baseline, compare against the baseline explicitly with `not.toEqual(baseline)` instead of a snapshot.","Update or delete the snapshot file to express the new expected value."],"exampleFix":"// before\nexpect(result).not.toMatchSnapshot();\n\n// after\nexpect(result).toMatchSnapshot();\n// or assert against an explicit value:\nexpect(result).not.toBe(oldValue);","handlingStrategy":"validation","validationCode":"// snapshots cannot be negated — drop the .not before calling\nfunction assertSnapshot(x: unknown) {\n  expect(x).toMatchSnapshot();\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat snapshot matchers as non-negatable; lint against `expect(*).not.toMatch*` if possible.","For 'value changed' assertions, compare against an explicit baseline with toEqual/not.toBe."],"tags":["snapshot","matcher","negation"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}