{"id":"011d556dda46e45d","repo":"jestjs/jest","slug":"matcherhintfromconfig-received-function-d","errorCode":null,"errorMessage":"${matcherHintFromConfig(...)}\n\nReceived function did not throw","messagePattern":"(.+?)\n\nReceived function did not throw","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/jest-snapshot/src/index.ts","lineNumber":525,"sourceCode":"      ),\n    );\n  }\n\n  let error;\n\n  if (fromPromise) {\n    error = received;\n  } else {\n    try {\n      received();\n    } catch (receivedError) {\n      error = receivedError;\n    }\n  }\n\n  if (error === undefined) {\n    // Because the received value is a function, this is not a matcher error.\n    throw new Error(\n      `${matcherHintFromConfig(config, false)}\\n\\n${DID_NOT_THROW}`,\n    );\n  }\n\n  let message = error.message;\n  while ('cause' in error) {\n    error = error.cause;\n    if (isError(error) || error instanceof Error) {\n      message += `\\nCause: ${error.message}`;\n    } else {\n      if (typeof error === 'string') {\n        message += `\\nCause: ${error}`;\n      }\n      break;\n    }\n  }\n\n  return _toMatchSnapshot({","sourceCodeStart":507,"sourceCodeEnd":543,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-snapshot/src/index.ts#L507-L543","documentation":"Thrown by the snapshot throw-matchers when the received function completed without throwing. After confirming the received value is a function and `.not` is not set, the matcher invokes `received()` inside a try/catch (index.ts:516-521); if no error was caught, `error === undefined` and this `DID_NOT_THROW` error is thrown. It is the snapshot-family equivalent of `expect(fn).toThrow()` failing.","triggerScenarios":"Calling `expect(fn).toThrowErrorMatchingSnapshot()` or `expect(fn).toThrowErrorMatchingInlineSnapshot()` where `fn` (or the promise it resolves, via the fromPromise path) does not throw any error.","commonSituations":"The function under test was refactored to no longer throw; the throw is conditional on state that isn't set up in this test; an async function was passed but resolved successfully where rejection was expected; the wrong function reference was passed.","solutions":["Verify the function actually throws under the test's current conditions by debugging or logging inside it.","If the function is async, ensure you pass a function that returns a rejected promise (or `await expect(fn).rejects.toThrowErrorMatchingSnapshot()`).","If the function is genuinely not supposed to throw, replace the matcher with `expect(fn).not.toThrow()`."],"exampleFix":"// before: getUser throws when id missing, but test passes a valid id\nexpect(() => getUser(validId)).toThrowErrorMatchingSnapshot();\n// after\nexpect(() => getUser(undefined)).toThrowErrorMatchingSnapshot();","handlingStrategy":"validation","validationCode":"// Prove the function throws before asserting it via the snapshot matcher\nfunction throwsUnder(fn, setup) {\n  setup?.();\n  try { fn(); return false; } catch { return true; }\n}\nif (!throwsUnder(fn, setupState)) throw new Error('precondition: fn must throw');","typeGuard":"const isThrowing = (fn: () => unknown): boolean => {\n  try { fn(); return false; } catch { return true; }\n};","tryCatchPattern":null,"preventionTips":["For async fns use `await expect(fn).rejects.toThrowErrorMatchingSnapshot()`.","Keep throw-condition setup right next to the assertion so the precondition is obvious.","If the throw is data-dependent, assert on the input that triggers it before the matcher."],"tags":["jest-snapshot","assertion-failure","throw-matcher"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}