jestjs/jest · error · Error
${matcherHint(...)} Expected properties must be an object ${
Error message
${matcherHint(...)} Expected properties must be an object
${printWithType('Expected properties', propertiesOrSnapshot, printExpected)} What it means
Thrown by `toMatchInlineSnapshot` (index.ts:234-249) when the call passes a `propertiesOrSnapshot` argument that is neither a string (treated as the inline snapshot) nor a non-null object (treated as expected properties). Same shape as the toMatchSnapshot guard but for inline variant.
Source
Thrown at packages/jest-snapshot/src/index.ts:238
const length = arguments.length;
if (length === 2 && typeof propertiesOrSnapshot === 'string') {
inlineSnapshot = propertiesOrSnapshot;
} else if (length >= 2) {
const options: MatcherHintOptions = {
isNot: this.isNot,
promise: this.promise,
};
if (length === 3) {
options.secondArgument = SNAPSHOT_ARG;
options.secondArgumentColor = noColor;
}
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),View on GitHub (pinned to f49721c78e)
Solutions
- Pass an object for properties, or a backtick string for the inline snapshot.
- If you don't want properties, drop the argument entirely so Jest writes the snapshot for you.
Example fix
// before
expect(x).toMatchInlineSnapshot(123);
// after
expect(x).toMatchInlineSnapshot(`123`);
// or, with properties:
expect(x).toMatchInlineSnapshot({ code: 123 }); Defensive patterns
Strategy: type-guard
Validate before calling
if (arg != null && typeof arg !== 'object' && typeof arg !== 'string') {
throw new Error('toMatchInlineSnapshot needs an object or string');
}
expect(x).toMatchInlineSnapshot(arg); Type guard
function isInlineSnapshotArg(v: unknown): v is object | string {
return v == null || typeof v === 'object' || typeof v === 'string';
} Prevention
- Author inline snapshot calls without arguments first; let Jest write the literal via -u.
- Pass properties as object literals at the call site.
When it happens
Trigger: `expect(x).toMatchInlineSnapshot(42)`, `expect(x).toMatchInlineSnapshot(null, 'snapshot')`, or `toMatchInlineSnapshot(true)`.
Common situations: Passing a primitive where an object or template-literal string is expected. Variable mistakenly null.
Related errors
- ${matcherHint(...)} Inline snapshot must be a string ${print
- ${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/06526f4c2164526a.json.
Report an issue: GitHub.