Testing with Enzyme (hooks)
This example repro shows how hook-based grid can be tested using Enzyme, Jest & React.
https://github.com/seanlandsman/ag-grid-react-hook-testing
Note that in this case, we use have to try wrap the App component within a forwardRef and expose the API with useImperitiveHandle.
Testing with Ezyme (components)
We have built an example for implementing Jest testing with React alongside ag-Grid.
Please find this example in a Github repository here:
https://github.com/seanlandsman/ag-grid-react-jest
In the example package, see the example tests that are set up here:
~/ag-grid-react-jest/src/App.test.js
An example using our latest version can be found here:
https://github.com/LouisMoore-agGrid/react-jest-enzyme-ag-grid-v22
Comments
2 comments
If I change the App component to function component. I can render the component in my browser perfectly fine and no difference than class component. But the unit test does not work anymore. function components have no this variable and that lead to result of null for component.instance(). Would you please provide another demo with function component using hooks also? Thank you!
I have a simple example here.
I figured out how to test it with Jest and Enzyme. But I do not know how to test it with react-testing-library, can you guide me through it?
Please sign in to leave a comment.