{"record":{"id":"e98bbdd98250f4a0","repo":"jestjs/jest","slug":"expected-color-expected-value-must-be-a-non","errorCode":null,"errorMessage":"${EXPECTED_COLOR('expected')} value must be a non-null object","messagePattern":"(.+?) value must be a non-null object","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/expect/src/matchers.ts","lineNumber":912,"sourceCode":"  toMatchObject(received: object, expected: object) {\n    const matcherName = 'toMatchObject';\n    const options: MatcherHintOptions = {\n      isNot: this.isNot,\n      promise: this.promise,\n    };\n\n    if (typeof received !== 'object' || received === null) {\n      throw new Error(\n        matcherErrorMessage(\n          matcherHint(matcherName, undefined, undefined, options),\n          `${RECEIVED_COLOR('received')} value must be a non-null object`,\n          printWithType('Received', received, printReceived),\n        ),\n      );\n    }\n\n    if (typeof expected !== 'object' || expected === null) {\n      throw new Error(\n        matcherErrorMessage(\n          matcherHint(matcherName, undefined, undefined, options),\n          `${EXPECTED_COLOR('expected')} value must be a non-null object`,\n          printWithType('Expected', expected, printExpected),\n        ),\n      );\n    }\n\n    const pass = equals(received, expected, [\n      ...this.customTesters,\n      iterableEquality,\n      subsetEquality,\n    ]);\n\n    const message = pass\n      ? () =>\n          // eslint-disable-next-line prefer-template\n          matcherHint(matcherName, undefined, undefined, options) +","sourceCodeStart":894,"sourceCodeEnd":930,"githubUrl":"https://github.com/jestjs/jest/blob/8e6d128e4a278059ecddecaa97400b04c8ae5fd9/packages/expect/src/matchers.ts#L894-L930","documentation":"Thrown by `toMatchObject` (matchers.ts:911) when the expected value is not a non-null object. The expected argument defines the subset of properties to verify, so it must be a plain object (or array, which is an object). Primitives, null, and undefined are rejected before the subset equality check.","triggerScenarios":"Calling `expect(obj).toMatchObject('a')` (string), `toMatchObject(5)` (number), `toMatchObject(null)`, or `toMatchObject(undefined)` — e.g. forgetting the expected argument or passing a primitive.","commonSituations":"Omitting the expected object entirely; passing a string key instead of an object descriptor; passing a value from a variable that resolved to undefined; copy-paste from a toHaveProperty call.","solutions":["Pass a non-null object describing the expected subset: toMatchObject({a: 1}).","If testing a single property value, use toHaveProperty('key', value) or toEqual instead.","Ensure the expected variable is a defined object, not undefined from a failed lookup.","For null checks use toBeNull; for existence use toHaveProperty."],"exampleFix":"// before\nexpect(obj).toMatchObject();\nexpect(obj).toMatchObject('id');\n\n// after\nexpect(obj).toMatchObject({id: 1});\n// single-value case\nexpect(obj).toHaveProperty('id', 1);","handlingStrategy":"type-guard","validationCode":"const expected = subset;\nif (typeof expected !== 'object' || expected === null) {\n  throw new Error('toMatchObject expected must be a non-null object');\n}\nexpect(obj).toMatchObject(expected);","typeGuard":"const isNonNullObject = (v: unknown): v is object =>\n  v !== null && typeof v === 'object';","tryCatchPattern":null,"preventionTips":["Always pass an object describing the expected subset.","Use toHaveProperty for single key/value checks.","Ensure the expected variable is a defined object."],"tags":["jest","expect","matcher","type-error","tomatchobject","object"],"backgroundTag":null,"analyzedSha":"8e6d128e4a278059ecddecaa97400b04c8ae5fd9","analyzedAt":"2026-08-10T18:11:27.960Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}