samedi 27 juin 2020

Testing react component that is dependent on Stateful Context Providers chain in React Testing Library

I'm aware of this, but it's not my case.

Example:

<AuthProvider>
  <SessionProvider>
    <AnotherProvider>
      <OneMoreProvider>
        <MyComponent />

All of these providers are actually regular React Components with state and effects, that fetch some data via GraphQL and pass that data as a 'value' prop to MyContext.Provider in return statement.

This enforces me to create lots of mocks for modules that are being used in all of these providers, just to render my own component in testing env.

Any thoughts about what can be done to avoid creating so many mocks?

Aucun commentaire:

Enregistrer un commentaire