{"id":"87c0f18c60ceb07d","repo":"jestjs/jest","slug":"matcherhint-inline-snapshot-must-be-a-stri","errorCode":null,"errorMessage":"${matcherHint(...)} Inline snapshot must be a string\n${printWithType('Inline snapshot', inlineSnapshot, serialize)}","messagePattern":"(.+?) Inline snapshot must be a string\n(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/jest-snapshot/src/index.ts","lineNumber":252,"sourceCode":"    if (\n      typeof propertiesOrSnapshot !== 'object' ||\n      propertiesOrSnapshot === null\n    ) {\n      throw new Error(\n        matcherErrorMessage(\n          matcherHint(matcherName, undefined, PROPERTIES_ARG, options),\n          `Expected ${EXPECTED_COLOR('properties')} must be an object`,\n          printWithType(\n            'Expected properties',\n            propertiesOrSnapshot,\n            printExpected,\n          ),\n        ),\n      );\n    }\n\n    if (length === 3 && typeof inlineSnapshot !== 'string') {\n      throw new Error(\n        matcherErrorMessage(\n          matcherHint(matcherName, undefined, PROPERTIES_ARG, options),\n          'Inline snapshot must be a string',\n          printWithType('Inline snapshot', inlineSnapshot, serialize),\n        ),\n      );\n    }\n\n    properties = propertiesOrSnapshot;\n  }\n\n  return _toMatchSnapshot({\n    context: this,\n    inlineSnapshot:\n      inlineSnapshot === undefined\n        ? undefined\n        : stripAddedIndentation(inlineSnapshot),\n    isInline: true,","sourceCodeStart":234,"sourceCodeEnd":270,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-snapshot/src/index.ts#L234-L270","documentation":"Thrown by `toMatchInlineSnapshot` (index.ts:251-259) in the 3-argument form when the third argument (the inline snapshot) is not a string. The 3-arg form is `toMatchInlineSnapshot(properties, inlineSnapshot)`, so the inline snapshot must be a string literal.","triggerScenarios":"`expect(x).toMatchInlineSnapshot({ a: 1 }, 123)` or `toMatchInlineSnapshot(props, { not: 'a string' })`. The third arg is meant to be a backtick template literal.","commonSituations":"Passing a serialized object instead of a string. Copy-paste from a non-inline matcher that accepts different argument types.","solutions":["Pass the inline snapshot as a backtick string: toMatchInlineSnapshot(props, `\"expected\"`).","Let Jest write it: call `toMatchInlineSnapshot(props)` with no third arg and run with `-u`."],"exampleFix":"// before\nexpect(x).toMatchInlineSnapshot({ code: 200 }, { body: 'ok' });\n\n// after\nexpect(x).toMatchInlineSnapshot(\n  { code: 200 },\n  `\n    Object {\n      \"body\": \"ok\",\n    }\n  `\n);","handlingStrategy":"type-guard","validationCode":"if (inlineSnapshot !== undefined && typeof inlineSnapshot !== 'string') {\n  throw new Error('Third arg to toMatchInlineSnapshot must be a string');\n}\nexpect(x).toMatchInlineSnapshot(props, inlineSnapshot);","typeGuard":"function isOptionalString(v: unknown): v is string | undefined {\n  return v === undefined || typeof v === 'string';\n}","tryCatchPattern":null,"preventionTips":["In the 3-arg form, always use a backtick template literal for the snapshot.","Omit the third arg and run with -u to let Jest populate it correctly."],"tags":["snapshot","matcher","argument-validation","inline-snapshot"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}