{"id":"6100ed2dbdee1454","repo":"jestjs/jest","slug":"matcherhintfromconfig-received-value-must","errorCode":null,"errorMessage":"${matcherHintFromConfig(...)} received value must be an object when the matcher has properties\n${printWithType('Received', received, printReceived)}","messagePattern":"(.+?) received value must be an object when the matcher has properties\n(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/jest-snapshot/src/index.ts","lineNumber":321,"sourceCode":"  if (snapshotState == null) {\n    // Because the state is the problem, this is not a matcher error.\n    // Call generic stringify from jest-matcher-utils package\n    // because uninitialized snapshot state does not need snapshot serializers.\n    throw new Error(\n      `${matcherHintFromConfig(config, false)}\\n\\n` +\n        'Snapshot state must be initialized' +\n        `\\n\\n${printWithType('Snapshot state', snapshotState, stringify)}`,\n    );\n  }\n\n  const fullTestName =\n    currentTestName && hint\n      ? `${currentTestName}: ${hint}`\n      : currentTestName || ''; // future BREAKING change: || hint\n\n  if (typeof properties === 'object') {\n    if (typeof received !== 'object' || received === null) {\n      throw new Error(\n        matcherErrorMessage(\n          matcherHintFromConfig(config, false),\n          `${RECEIVED_COLOR(\n            'received',\n          )} value must be an object when the matcher has ${EXPECTED_COLOR(\n            'properties',\n          )}`,\n          printWithType('Received', received, printReceived),\n        ),\n      );\n    }\n\n    const propertyPass = context.equals(received, properties, [\n      context.utils.iterableEquality,\n      context.utils.subsetEquality,\n    ]);\n\n    if (propertyPass) {","sourceCodeStart":303,"sourceCodeEnd":339,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-snapshot/src/index.ts#L303-L339","documentation":"Thrown by `_toMatchSnapshot` (index.ts:319-332) when properties are supplied to the matcher but `received` is not a non-null object. Property-subset matching (`context.equals(received, properties, ...)`) only makes sense when both sides are objects; passing properties against a primitive is a usage error.","triggerScenarios":"`expect(42).toMatchSnapshot({ min: 0 })`, `expect('hello').toMatchInlineSnapshot({ length: 5 })`, `expect(null).toMatchSnapshot({})`.","commonSituations":"Passing a primitive where an object was intended. Accidentally including a properties argument for a scalar assertion.","solutions":["Drop the properties argument when asserting on a primitive: `expect(42).toMatchSnapshot()`.","Wrap the value in an object if you really want property matching: `expect({ value: 42 }).toMatchSnapshot({ value: expect.any(Number) })`.","Assert the primitive directly with a string snapshot."],"exampleFix":"// before\nexpect(statusCode).toMatchSnapshot({ min: 200 });\n\n// after\nexpect({ statusCode }).toMatchSnapshot({ statusCode: expect.any(Number) });","handlingStrategy":"type-guard","validationCode":"if (typeof received !== 'object' || received === null) {\n  throw new Error('Received must be a non-null object when using properties');\n}\nexpect(received).toMatchSnapshot(properties);","typeGuard":"function isNonNullObject(v: unknown): v is object {\n  return typeof v === 'object' && v !== null;\n}","tryCatchPattern":null,"preventionTips":["Only pass properties to snapshot matchers when the received value is an object.","For primitives, drop the properties argument or wrap the value."],"tags":["snapshot","matcher","argument-validation","properties"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}