Open Rishabh-malhotraa opened 2 years ago
@Rishabh-malhotraa we could use Jest to mock services and generate snapshots for each page. Was this what you had in mind?
Well, I haven't really done a lot of testing myself. I need to do some research about this; I was just thinking of a basic unit test to tell if the updates crash the app or not. Do you mind elaborating your approach a bit?
@Rishabh-malhotraa sure!
Using this approach, Jest will render a React component using a lightweight test render and generate an HTML output, this output is referred to as a snapshot. Asynchronous operations like API responses should be mocked to ensure that the tests run quickly and only app functionality is tested, not the APIs the app calls.
Each time a test is run, the component is rendered and compared to the snapshot. If they are not equal, the test fails. At this point you'll need to decide if the changes to the HTML were intended, if they were, you'll need to update the snapshot to the render result of the latest test run.
Pros of snapshot testing:
Cons of snapshot testing:
Sorry if I'm not doing a great job explaining this, check the docs for more info
I suggested this because it would (imo) be the fastest way to setup some initial tests that can verify if new changes break the app or have unintended side effects.
Ideally you'd have unit tests as well to test individual classes/methods, I just thought snapshots might be a good starting point. I'm fairly new to client side testing too though - I'm interested to hear what you think 😄
I suggested this because it would (imo) be the fastest way to setup some initial tests that can verify if new changes break the app or have unintended side effects.
Ideally you'd have unit tests as well to test individual classes/methods, I just thought snapshots might be a good starting point. I'm fairly new to client side testing too though - I'm interested to hear what you think smile
Using just snapshot testing is not quite helpful, try to test all API calls, fire events, state of app, existence of children in different renders and other functionality of the app, i will join you to write unit test for all the components in coming days, please spend a little time on React Testing Library, it will help to guide you in a right way.
https://testing-library.com/docs/react-testing-library/intro/
Using just snapshot testing is not quite helpful, try to test all API calls, fire events, state of app, existence of children in different renders and other functionality of the app, i will join you to write unit test for all the components in coming days, please spend a little time on React Testing Library, it will help to guide you in a right way.
https://testing-library.com/docs/react-testing-library/intro/
Sounds good, I'll start playing around with React Testing Library 😄
This will be alot of work! Might I suggest breaking this down into smaller issues so the PRs are easier to review?
That's great, go ahead.
Requirement