GithubHelp home page GithubHelp logo

Comments (3)

gaearon avatar gaearon commented on May 3, 2024

It depends on what behavior you would like to test.

from ama.

chentsulin avatar chentsulin commented on May 3, 2024

When I implement a module something like api middleware in redux real world example, I found I don't really know how to well test it. Then I split it into middleware, api utils, schemas three files and try to follow single responsibility principle.

Maybe I Just want to avoid introducing some stupid bugs when I modified some code. I usually mock third party libraries in unit tests and then test they have been called correctly, but it seems cumbersome when a lot of .then call. Hope to hear some your advice or your past experience here.

from ama.

gaearon avatar gaearon commented on May 3, 2024

I'd just mock fetch and verify that different API responses handled in different order produce a state that makes sense. If I needed to test something more specific, I'd split the function and test its parts separately.

from ama.

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.