{"id":"9ec044d2d3d160c1","repo":"jestjs/jest","slug":"matcherhint-expected-properties-must-be-an","errorCode":null,"errorMessage":"${matcherHint(...)} Expected properties must be an object\n${printedWithType}","messagePattern":"(.+?) Expected properties must be an object\n(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/jest-snapshot/src/index.ts","lineNumber":189,"sourceCode":"        promise: this.promise,\n      };\n      let printedWithType = printWithType(\n        'Expected properties',\n        propertiesOrHint,\n        printExpected,\n      );\n\n      if (length === 3) {\n        options.secondArgument = 'hint';\n        options.secondArgumentColor = BOLD_WEIGHT;\n\n        if (propertiesOrHint == null) {\n          printedWithType +=\n            \"\\n\\nTo provide a hint without properties: toMatchSnapshot('hint')\";\n        }\n      }\n\n      throw new Error(\n        matcherErrorMessage(\n          matcherHint(matcherName, undefined, PROPERTIES_ARG, options),\n          `Expected ${EXPECTED_COLOR('properties')} must be an object`,\n          printedWithType,\n        ),\n      );\n    }\n\n    // Future breaking change: Snapshot hint must be a string\n    // if (arguments.length === 3 && typeof hint !== 'string') {}\n\n    properties = propertiesOrHint;\n  }\n\n  return _toMatchSnapshot({\n    context: this,\n    hint,\n    isInline: false,","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-snapshot/src/index.ts#L171-L207","documentation":"Thrown by `toMatchSnapshot` (index.ts:189-195) when the matcher is called with two or three arguments and the second argument is neither a string (treated as a hint) nor a non-null object (treated as expected properties). The runtime can't decide what the caller meant, so it surfaces a typed matcher error via `matcherErrorMessage`.","triggerScenarios":"`expect(x).toMatchSnapshot(123)`, `expect(x).toMatchSnapshot(true)`, or `expect(x).toMatchSnapshot(undefined, 'hint')` (the `undefined` is the offending second arg in a 3-arg call).","commonSituations":"Passing a variable that was meant to be an object but is `undefined`/a primitive. Mixing up argument order between properties and hint.","solutions":["Pass an object as the second argument when you mean properties: `toMatchSnapshot({ a: 1 })`.","Pass a string when you mean a hint: `toMatchSnapshot('hint')`.","For a 3-arg call `toMatchSnapshot(properties, 'hint')`, ensure the first is a non-null object and the second a string."],"exampleFix":"// before\nexpect(result).toMatchSnapshot(statusCode); // statusCode is a number\n\n// after\nexpect(result).toMatchSnapshot({ statusCode });","handlingStrategy":"type-guard","validationCode":"function isPropertiesOrHint(v: unknown): v is object | string {\n  return v == null || typeof v === 'object' || typeof v === 'string';\n}\nif (!isPropertiesOrHint(arg)) {\n  throw new Error('Pass an object for properties or a string for a hint');\n}\nexpect(x).toMatchSnapshot(arg);","typeGuard":"function isProperties(v: unknown): v is object {\n  return typeof v === 'object' && v !== null;\n}\nfunction isHint(v: unknown): v is string {\n  return typeof v === 'string';\n}","tryCatchPattern":null,"preventionTips":["When you want properties, pass a plain object literal at the call site.","When you want a hint, pass a string literal.","Avoid optional-chained variables as the second arg unless you've checked them."],"tags":["snapshot","matcher","argument-validation"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}