jestjs/jest · error · Error
${matcherHint(...)} Inline snapshot must be a string ${print
Error message
${matcherHint(...)} Inline snapshot must be a string
${printWithType('Inline snapshot', inlineSnapshot, serialize)} What it means
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.
Source
Thrown at packages/jest-snapshot/src/index.ts:252
if (
typeof propertiesOrSnapshot !== 'object' ||
propertiesOrSnapshot === null
) {
throw new Error(
matcherErrorMessage(
matcherHint(matcherName, undefined, PROPERTIES_ARG, options),
`Expected ${EXPECTED_COLOR('properties')} must be an object`,
printWithType(
'Expected properties',
propertiesOrSnapshot,
printExpected,
),
),
);
}
if (length === 3 && typeof inlineSnapshot !== 'string') {
throw new Error(
matcherErrorMessage(
matcherHint(matcherName, undefined, PROPERTIES_ARG, options),
'Inline snapshot must be a string',
printWithType('Inline snapshot', inlineSnapshot, serialize),
),
);
}
properties = propertiesOrSnapshot;
}
return _toMatchSnapshot({
context: this,
inlineSnapshot:
inlineSnapshot === undefined
? undefined
: stripAddedIndentation(inlineSnapshot),
isInline: true,View on GitHub (pinned to f49721c78e)
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`.
Example fix
// before
expect(x).toMatchInlineSnapshot({ code: 200 }, { body: 'ok' });
// after
expect(x).toMatchInlineSnapshot(
{ code: 200 },
`
Object {
"body": "ok",
}
`
); Defensive patterns
Strategy: type-guard
Validate before calling
if (inlineSnapshot !== undefined && typeof inlineSnapshot !== 'string') {
throw new Error('Third arg to toMatchInlineSnapshot must be a string');
}
expect(x).toMatchInlineSnapshot(props, inlineSnapshot); Type guard
function isOptionalString(v: unknown): v is string | undefined {
return v === undefined || typeof v === 'string';
} Prevention
- 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.
When it happens
Trigger: `expect(x).toMatchInlineSnapshot({ a: 1 }, 123)` or `toMatchInlineSnapshot(props, { not: 'a string' })`. The third arg is meant to be a backtick template literal.
Common situations: Passing a serialized object instead of a string. Copy-paste from a non-inline matcher that accepts different argument types.
Related errors
- ${matcherHint(...)} Expected properties must be an object ${
- ${matcherHint(...)} Expected properties must be an object ${
- ${matcherHintFromConfig(...)} received value must be an obje
- ${matcherHint(...)} received value must be a function ${prin
- Jest: Couldn't infer stack frame for inline snapshot.
AI-assisted analysis of jestjs/jest@f49721c78e (2026-08-03).
Data as JSON: /data/errors/87c0f18c60ceb07d.json.
Report an issue: GitHub.