-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[data grid] Testing with react testing library #1151
Comments
@benjamin-schneider Did you find a solution? I have looked at this problem a few months ago when I started to share the testing stack of the main repository with this one. I have stopped looking after failing to make the AutoSizer return my fake data in jsdom. So I ended up adding: I'm reopening because it's important. Developers should be able to tests their grid without having to rely on an actual browser as we do (it's not very common for UI components tests inside web applications). As far as I have pushed the exploration, I can think of two paths:
If you are using jest, you could probably mock the component as it's done in bvaughn/react-window#454 (comment). A bit of caution. I'm not completely sure that it's something that possible. jsdom might be missing some APIs in order for the grid to work well. This is not a simple button component. |
try to wrap your <div style={{ width: 300, height: 300 }}>
<DataGrid .../>
</div>, |
@dtassone jsdom has no layout capabilities, the width/height would have no effects. |
@oliviertassinari Hi, thanks for your anwser. I did not find a solution, I just closed to avoid polluting your issues as I was thinking I was maybe wrong.
This was just a five minutes try... |
@benjamin-schneider I have also spent 5 minutes looking at this yesterday. After solving the autosize issue, I was facing a .scrollTo missing API in jsdom 🙈. I have stopped there because I had to look at more pressing matters. I have added the |
@oliviertassinari How about we add 2 props to force the height and width of AutoSizer |
@dtassone Yeah, maybe we could do this for test only purposes. It could solve one part of the issue. I think that we need to understand all the implications of supporting the rendering inside jsdom before making changes. There might be even bigger issues. I also think that we can wait for more upvotes before dedicating time to it. It's unclear if developers want this. Intuitively, I would assume that many want it, but it seems costly, so if we can live without it, that's even better 🙃. |
just chiming in to say I'm having a bear of a time trying to test for row content in @material-ui/core/DataGrid. Tried everything in the past 48 hours & can't get the rows to even render within ReactTestingLibrary UPDATE: finally got stuff to render. needed the "autoheight" param. for some reason it renders in the browser but not in the tests. needs autoheight. go figure |
@DavidHanover The |
Since you're wondering, we're also feeling this pain. We've been using Xgrid for about 4 mos, and felt almost immediate pain since we're a TDD shop. Found a workaround with alpha18 by setting a fixed width on the Grid's parent tied to a theme variable being set in test env only, but that stopped working in alpha24. BTW, we're testing with jest + RTL. |
Making sure the right columns are displayed was our first round of tests where we ran into issues.
Making sure the data is run through the correct formatting rules (colDef valueFormatter, etc)
Making sure the react component using the table updated it with the correct data
Making sure the click actions do the right thing
… On Apr 10, 2021, at 5:34 PM, Olivier Tassinari ***@***.***> wrote:
@gap777 <https://github.com/gap777> What aspects are you testing on the data grid? Are you testing simple interactions, like what rows are displayed or more?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#1151 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ABRR26RNT5PXSFZKQPGBQEDTIC76LANCNFSM4YQ7LFFQ>.
|
@gap777 Ok great. This is covered by #1361. For closing the issue. I would propose the following requirements:
On the approach, I could find this interesting comment. ag-grid/ag-grid#4165 (comment). They have a prop to disable the virtualization. I guess we will know more about the challenges with our grid as me make progress on 2. |
Since #1361, we now run 69% of our tests inside jsdom (and 100% inside real browsers). |
Very good job with the coverage improvements, thanks ! import type { DataGridProps } from '@material-ui/data-grid';
jest.mock('@material-ui/data-grid', () => {
const { DataGrid } = jest.requireActual('@material-ui/data-grid');
return {
...jest.requireActual('@material-ui/data-grid'),
DataGrid: (props: DataGridProps) => {
return (
<DataGrid
{...props}
autoHeight
/>
);
},
};
}); |
This is still causing me major issues :( Even if I look for row in my test It only slightly increase test coverage as opposed to the large increase when using a failing test that looks for the specific text I expect to be found in a cell after an API call is placed. Hopping to see a further resolution of this issue come down the pipe. |
@Eyegee-Eleven do you have an example of a case you can't test? (please provide a codesandbox). |
The problem still exists for me. Neither
|
I'm having this issue. I have a button that, when clicked, adds a row to the DataGrid and places that row into edit mode. The row is added, but it never enters edit mode each cell is only a self-closing DIV. |
@Rafael805 , @n-junge have you tried adding @ModPhoenix's solution? You can add it before the |
This comment was marked as off-topic.
This comment was marked as off-topic.
@dnikhila I've observed the same issue here: adoptium/adoptium.net#1758 |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
I'm seeing |
I was also having trouble writing tests. Using renderCell seems to be the culprit as the tests pass when I remove all of the column definitions that use this function. #1151 (comment) resolved the issue. |
Had issues with rendering all the columns in the grid. The |
For me, it worked only after I used |
I'm using |
hey everyone! I am experiencing the same issue after updating the data-grid package from version More concretely, upgrading the version made a test faling. This test is executing some filtering and checking if the rows are filtered correctly. The problem is that the rowCount is showing a number, but not all of the rows are being rendered on the tests. I tried the solution proposed by @ModPhoenix of adding the I am using the next react testing library versions:
Any thoughts on how can be fixed? Thanks a lot in advance! |
Hi, We are having exact same issue. Only header of first 3 columns are rendering. I tried suggested solutions above but they are not working. We are using MUIDataTable with vitest. Here is the mock function we are using |
With the component
@material-ui/data-grid
I am unable to get the rows rendered in a jest / react-testing-library environment. I use jest and material-ui since years, and this is the first time I do not manage to find any solution.Current Behavior 😯
I want to test a fully renderer datagrid. To test if a cell in a row il well formatted, to test row clicks, etc. Unfortunately, I don't manage to render the rows. In debug mode, I get :
I saw this line in the internal tests : https://github.com/mui-org/material-ui-x/blob/master/packages/grid/x-grid/src/tests/rows.XGrid.test.tsx#L43
Maybe it it actually not possible to achieve testing rows :(
Expected Behavior 🤔
I would like datagrid to fully render in a jest/jestdom env.
Steps to Reproduce 🕹
Here is a very minimal repro to isolate :
First test (cols or headings) passes, testing rows fails
Your Environment 🌎
Ubuntu 20.04 / jest
Progress on the solution
#1151 (comment)
The text was updated successfully, but these errors were encountered: