edges not rendered to JSDOM when testing with Jest and React Testing Library
See original GitHub issueHi!
I’m having some issue on making the nodes and edges to show up when I’m rendering the graph to JSDOM with Jest and React Testing Library. I have the following set up:
//App.js
import ReactFlow from "react-flow-renderer";
const App = () => (
<ReactFlow
elements={[
{
data: { label: "a" },
id: "b",
position: { x: 10, y: 10 },
},
{
data: { label: "b" },
id: "a",
position: { x: 10, y: 80 },
},
{
id: "edge-a-b",
source: "a",
target: "b",
},
]}
/>
);
And then I try to test it:
//App.test.js
import { render } from "@testing-library/react";
import App from "./App";
it("should render", async () => {
const { debug, getByText } = render(<App />);
debug();
expect(getByText("a")).toBeInTheDocument();
});
The test fails because the node is not rendered. If I do a debug, I can see that the wrapper elements for the graph are being rendered, but no nodes or edges.
<body>
<div>
<div
class="react-flow"
>
<div
class="react-flow__renderer react-flow__zoompane"
>
<div
class="react-flow__nodes"
style="transform: translate(0px,0px) scale(1);"
/>
<svg
class="react-flow__edges"
height="500"
width="500"
>
<defs>
<marker
class="react-flow__arrowhead"
id="react-flow__arrowclosed"
markerHeight="12.5"
markerWidth="12.5"
orient="auto"
refX="0"
refY="0"
viewBox="-10 -10 20 20"
>
<polyline
fill="#b1b1b7"
points="-5,-4 0,0 -5,4 -5,-4"
stroke="#b1b1b7"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="1"
/>
</marker>
<marker
class="react-flow__arrowhead"
id="react-flow__arrow"
markerHeight="12.5"
markerWidth="12.5"
orient="auto"
refX="0"
refY="0"
viewBox="-10 -10 20 20"
>
<polyline
fill="none"
points="-5,-4 0,0 -5,4"
stroke="#b1b1b7"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="1.5"
/>
</marker>
</defs>
<g
transform="translate(0,0) scale(1)"
/>
</svg>
<div
class="react-flow__pane"
/>
</div>
</div>
</div>
</body>
I wanted to set up a codesandbox, but I couldn’t get to polyfill ResizeObserver.
Any ideas on what might be going on and how to ‘fix’ it?
EDIT: if I pass a callback to onLoad, I can see the elements in there:
import ReactFlow from "react-flow-renderer";
const App = () => {
const onLoad = (instance) => {
console.log(instance.getElements());
};
return (<ReactFlow elements={[...]} onLoad={onLoad} />);
};
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:31 (11 by maintainers)
Top Results From Across the Web
Setup - Testing Library
In these docs we'll demonstrate configuring Jest, but you should be able to do similar things with any testing framework (React Testing Library...
Read more >Target container is not a DOM element. while testing ...
The reason this happens is the document generated by jest is empty, it does not contain your root div , so you should...
Read more >Understanding how react-testing-library works with Kent C ...
Kent walks us through the internals of dom-testing-library and react-testing-library. There is a lot of set-up and tear down when testing UI components....
Read more >Our Journey From JSDOM and React Testing Library Toward ...
We're diving into why and how we've migrated from Jest and React Testing Library (RTL) to Cypress Component Testing (CCT) for UI integration ......
Read more >Setting up Jest + React-Testing-Library - DEV Community
Examples; Curated resources to help you get started with RTL. File structure: Article I wrote on How I structure my React Apps (not...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I put it in the test file itself (eg: MyComponent.test.tsx) inside
beforeAll. Below is my setup:@moklick I think it would be useful to add an example to the site. Most people use Jest + Testing Library in their application, and setting up tests is a bit challenging.
Hey everyone,
I looked into this but I haven’t found a good solution yet. There are two problems:
"[TypeError: window.DOMMatrixReadOnly is not a constructor"I don’t understand why this is not supported by jest or why I can’t find anything about it. It’s a dom library that is supoorted by all browsers https://developer.mozilla.org/en-US/docs/Web/API/DOMMatrixReadOnlyCan anyone help here?