-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error clicking node in React Flow in jest test with @testing-library #2587
Comments
hey! Did you see this issue #2461 (comment) ? Does it solve your problem? |
I did, but now I did again and it worked, because I removed |
I am glad it worked out! |
It's not very optimal thought for testing purposes, as I cannot select node at the moment either. But at least I can make some of the tests work now, it's a start. |
Why can't you select a node? |
I can select node, but not with just mouse click. Could be something with how my custom node is built, as it is selectable by space after clicking it and it can be selected by tab. Anyway was able to get around it. Thanks again! |
I'd like to be able to write a test that clicks on a node to select: await waitFor(() =>
userEvent.click(canvas.getByRole(/* code to click on a specific node */)),
); But this errors with "Cannot read properties of null (reading 'document')". Disabling dragging works, but I don't want to disable it, as it's a feature we're using. I understand this is an upstream issue, but would be good to track it. |
I will open a new issue against d3-drag, as the previous one was closed without a fix |
Upstream issue and PR raised |
In the meantime, I think this can be resolved by either: userEvent.click(canvas.getByRole(/* */), {
view: window,
}), or mocking window if running in a non browser environment, maybe something like: userEvent.click(canvas.getByRole(/* */), {
view: new JSDOM().window,
}), |
Thanks for a great library! @penx Did you manage to find a better solution? My setup:
My bug:
The issue:
This is my problem Thanks! |
I don't have access to the code where I had this issue anymore, but pretty sure my last comment above was working for us |
Thanks @penx, user-event v14 API has changed the API and I haven't figured out to achieve the same thing there... :/ |
Describe the Bug
We have test runned with jest and react-testing-library. When test is run, everything works fine until node or any element inside node is clicked:
I have tried to add
nodesDraggable={false}
toReactFlow
andclassName='nodrag'
to Node, but that doesn't help. We have added needed lines described in documentation totestUtils.ts
. Nodes and elements inside nodes are rendered and pass test.Your Example Website or App
No response
Steps to Reproduce the Bug or Issue
Unfortunately can't share any actual code, other than test case:
That's pretty much is failing test case. Last line produces the error.
Wrapper includes mocks to redux store, API calls, history and GraphQL (moving to GQL, but still using some legacy for a while) and everything with those seem to work, as nodes are rendered.
Expected behavior
As a user I expect Node to be selected with no error and I can further test my app.
Screenshots or Videos
No response
Platform
Additional context
No response
The text was updated successfully, but these errors were encountered: