You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import { initialTestState } from '../../../redux_test_stores/test_store';
379
379
380
380
describe(<MyComponent />, () => {
381
-
let store;
382
381
let container;
383
382
const mockStore = configureStore([thunk]);
384
-
store = mockStore(initialTestState);
383
+
const store = mockStore(initialTestState);
385
384
386
385
beforeEach(() => {
387
386
// setup a DOM element as a render target
@@ -445,7 +444,7 @@ Some things to consider testing:
445
444
446
445
Some tests throw errors if a part of the client-side code tries to make an API call or AJAX request. Our solution to this is to use jest to replace those functions with [mock functions](https://jestjs.io/docs/mock-functions).
447
446
448
-
The code in question for the client side is mostly related to the axios library. We mock the whole library - jest automatically does this since we have an ``axios.js`` file in the ``__mocks__`` folder at the root of the client folder. [1][2]
447
+
The code in question for the client side is mostly related to the axios library. We mock the whole library - jest automatically does this since we have an ``axios.js`` file in the ``__mocks__`` folder at the root of the client folder. [[2]](#References)
449
448
450
449
The benefit of this is that you can control exactly what happens when any axios function gets called, and you can check how many times it's been called.
451
450
@@ -466,7 +465,7 @@ Testing multiple components together. A small example is rendering a parent comp
466
465
Most of our tests are of this type. In this, you're testing a the functionality of a single component and no more.
467
466
468
467
## Internationalization
469
-
Project uses i18n.
468
+
This project uses i18next for internationalization. If you import the render function with the i18n wrapper from ``test_utils.js``, it's set up to use English, so the components with be rendered with English text and you should be able to count on this to test for specific strings.
470
469
471
470
## Tips
472
471
1. Make test fail at least once to make sure it was a meaningful test
- [More info on this method](https://stackoverflow.com/questions/51393952/mock-inner-axios-create/51414152#51414152)
482
-
- [and this too](https://medium.com/asos-techblog/how-to-test-your-react-redux-application-48d90481a253)
479
+
1. [Best practices for unit testing with a react redux approach](https://willowtreeapps.com/ideas/best-practices-for-unit-testing-with-a-react-redux-approach)
480
+
481
+
2. [How to test your react-redux application (this article also references axios)](https://medium.com/asos-techblog/how-to-test-your-react-redux-application-48d90481a253)
0 commit comments