Skip to content

Commit

Permalink
use createRoot for snapshots when available
Browse files Browse the repository at this point in the history
  • Loading branch information
robinweser committed Apr 6, 2022
1 parent 9aeea63 commit 34c3537
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 31 deletions.
Empty file.
1 change: 1 addition & 0 deletions packages/fela-integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"fela-monolithic": "^12.0.2",
"fela-tools": "^12.0.2",
"jest-react-fela": "^12.0.2",
"jsdom": "^19.0.0",
"raf": "^3.4.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
Expand Down
22 changes: 21 additions & 1 deletion packages/jest-react-fela/src/createSnapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,29 @@ import { RendererProvider, ThemeProvider } from 'react-fela'

import { createSnapshotFactory } from 'jest-fela-bindings'

let createRoot
try {
const ReactDOMClient = require('react-dom/client')
if (
typeof ReactDOMClient !== 'undefined' &&
typeof ReactDOMClient.createRoot !== 'undefined'
) {
createRoot = ReactDOMClient.createRoot
}
} catch (e) {}

function renderComponent(component, node) {
if (createRoot) {
const root = ReactDOMClient.createRoot(component)
root.render(node)
} else {
render(component, node)
}
}

export default createSnapshotFactory(
createElement,
render,
renderComponent,
createRenderer(),
RendererProvider,
ThemeProvider
Expand Down
Loading

1 comment on commit 34c3537

@vercel
Copy link

@vercel vercel bot commented on 34c3537 Apr 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.