Fix Jest snapshot tests for React 19


TL;DR: add overrides to package.json:

"overrides": {
  "pretty-format": {
    "react-is": "$react"
  }
}

Problem

When upgrading to React 19, Jest snapshot tests fail with the error:

Error: expect(received).toMatchSnapshot()

Snapshot name: `domToReact converts single DOM node to React 1`

- Snapshot  -  3
+ Received  + 10

- <p>
-   foo
- </p>
+ {
+   "$$typeof": Symbol(react.transitional.element),
+   "_owner": null,
+   "_store": {},
+   "key": null,
+   "props": {
+     "children": "foo",
+   },
+   "type": "p",
+ }

    at Object.<anonymous> (__tests__/dom-to-react.test.tsx:24:26)

This happens because React changed Symbol.for('react.element') to Symbol.for('react.transitional.element').

Solution

Follow this comment and set overrides for react-is in package.json:

{
  "overrides": {
    "pretty-format": {
      "react-is": "19"
    }
  }
}

See example.

If the react version is specified in dependencies, you can reference the value with $react:

{
  "dependencies": {
    "react": "19"
  },
  "overrides": {
    "pretty-format": {
      "react-is": "$react"
    }
  }
}

See example.

If you’re using Yarn, set resolutions:

{
  "resolutions": {
    "react-is": "$react"
  }
}


Please support this site and join our Discord!