Categories
android internet tech

react: Enable Unit Tests for Components using Redux

When migrating to redux we wish to make certain that each and every part that is dependent upon redux has get entry to to the redux retailer. To do this we use the <Provider> part. We can use that during each and every person unit check or in some more or less wrapper.

This lesson demonstrates each approaches and ends with developing our personal model or @testing-library/reacts render manner, that can mechanically wrap all elements in a <Provider> with our redux retailer.

More details about this way will also be discovered right here: https://redux.js.org/recipes/writing-tests#connected-components

If you might be using Enzyme you could to find the mountWithStore software from enzyme-redux serves a equivalent goal.


Note:

The reduxRender serve as proven on this lesson if truth be told features a typo, in keeping with the place the choices are unfold. The proper model must seem like:

const reduxRender = (ui, choices) => render(ui, { wrapper: ReduxProvider, ...choices });