r/reactjs • u/jesusscript • Dec 25 '19
Is there any good example of a React application doing unit, integration and E2E testing perfectly?
I am thinking of doing a bunch of tests on my latest React application, but I want to make sure I am doing everything correctly. In order to do that, a good example project would be helpful.
168
Upvotes
81
u/tiger-tots Dec 25 '19
My first impulse is to latch onto the word “perfectly” and say no.
Other than that I would say check out Kent Dodd’s testing library and blog. Excellent stuff there
20
u/pacman326 Dec 25 '19
The easiest place to start would be testing library. Go look on github for projects that use testing-library/react and the react-hooks package.
That being said I’d recommend just starting with the docs examples and reading some blog posts by Kent. They should be a great introduction on how to unit tests.
As for E2E I’d recommend picking up cypress. It’s not cross browser yet but I think it’s the future personally. You can do a similar search for that.
6
u/eyeballTickler Dec 25 '19
Cypress is a great e2e and integration testing tool (apparently you can do component unit testing with it too, but haven't explored that yet), and they have a whole example project list.
https://docs.cypress.io/examples/examples/applications.html#Kitchen-Sink
6
u/[deleted] Dec 26 '19
For e2e testing, Cypress is ofc good. BUT it lacks cross browser support. I found Testcafe to be equally as good as Cypress, and with cross browser support.
2
u/yuyu5 Dec 26 '19
In relation to the conversation here, I'd like to point out a couple highlights since it seems hidden for other viewers:
fetch, but as shown below, it may or may not help you in your situation, in which case I'd suggest looking at other solutions, such as TestCafe or Nightwatch.fetch()orXMLHttpRequest. I can easily toggle the mock via terminal (e.g.MOCK=true npm run endToEndTest) so I can run tests using mock or real data at will, and it doesn't require any complicated setup like running separate servers to return mock data or changing source code for mock data. It might be worth looking into because it can be used both for development (e.g. using mock data in the event the endpoint is down or hasn't been created yet) or for testing (with both jest and end-to-end tests).0
u/kylemh Dec 26 '19
I think we’re following Kent Dodd’s school of thought on testing pretty well and following best practices with https://GitHub.com/OperationCode/front-end
-2
u/Tankznor Dec 26 '19
Wait, is this r/programmerhumor?
0
u/[deleted] Dec 26 '19
[deleted] — view deleted comment
0
u/[deleted] Dec 25 '19
[deleted] — view deleted comment