Giter Club home page Giter Club logo

Comments (7)

GregDevProjects avatar GregDevProjects commented on August 11, 2024

@Rishabh-malhotraa we could use Jest to mock services and generate snapshots for each page. Was this what you had in mind?

from caucus.

Rishabh-malhotraa avatar Rishabh-malhotraa commented on August 11, 2024

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?

from caucus.

GregDevProjects avatar GregDevProjects commented on August 11, 2024

@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:

  1. Tests can be created quickly
  2. Unintended changes are quickly revealed
  3. Component logic can be tested without extracting the code into separate functions

Cons of snapshot testing:

  1. Repository size will increase significantly (the snapshots must be stored in the repo)
  2. It can be difficult to track down why the test failed, especially if the tested component has alot of logic

Sorry if I'm not doing a great job explaining this, check the docs for more info

from caucus.

GregDevProjects avatar GregDevProjects commented on August 11, 2024

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 😄

from caucus.

MarufSharifi avatar MarufSharifi commented on August 11, 2024

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/

from caucus.

GregDevProjects avatar GregDevProjects commented on August 11, 2024

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?

from caucus.

MarufSharifi avatar MarufSharifi commented on August 11, 2024

That's great, go ahead.

from caucus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.