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
Copy file name to clipboardExpand all lines: developer_docs/testing.md
+19-4Lines changed: 19 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -22,6 +22,7 @@ Many files still don't have tests, so **if you're looking to get started as a co
22
22
-[Internationalization](#internationalization)
23
23
-[Useful terminology to know](#Useful-terminology-to-know)
24
24
-[Tips](#Tips)
25
+
-[Files to start with](#Files-to-start-with)
25
26
-[More resources](#More-resources)
26
27
-[References](#References)
27
28
@@ -219,7 +220,7 @@ Node modules are mocked in the ``__mocks__`` folder at the root of the client fo
219
220
### test-utils.js
220
221
This file overwrites the default react-testing-library's render function so that components rendered through the new render function have access i18next and redux. It exports the rest of react-testing-library as is.
221
222
222
-
It exports a render function with a i18n wrapper as ``render`` and a render function with a wrapper for both redux and i18n as ``reduxRender``
223
+
It exports a render function with a i18n wrapper as ``render`` and a render function with a wrapper for both redux and i18n as ``reduxRender``.
223
224
224
225
Thus, in your component test files, instead of calling ``import {functions you want} from 'react-testing-libary'`` importing react-testing library might look something like this:
225
226
@@ -259,6 +260,12 @@ function reduxRender(
259
260
}
260
261
```
261
262
263
+
Then, if you want to call the render function with the wrapper with the Redux Provider, you can do this, once you have a [store made with redux-mock-store](#Connected-Components):
264
+
265
+
```js
266
+
reduxRender(<SketchList {...subjectProps} />, { store });
267
+
```
268
+
262
269
263
270
### testData
264
271
This folder contains the test data that you can use in your tests, including inital redux states that you can provide to the ``reduxRender`` function when testing. For example, if you want to render the SketchList component with a username of ``happydog`` and some sample sketches, ``testData/testReduxStore.js`` contains a definition for that state that you can import and provide to the renderer. The folder also contains test data that you can use for ``msw`` server so that the server returns json with the correct format and fields.
You can see it used in the context of a test [in the SketchList.test.jsx file](../client/modules/IDE/components/SketchList.test.jsx).
464
471
472
+
## Internationalization
473
+
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.
474
+
465
475
466
476
## Useful terminology to know
467
477
Thanks [Test Double Wiki](https://github.com/testdouble/contributing-tests/wiki/Test-Double) for the definitions. You might see some of these words used in testing library documentation, so here are short definitions for them.
@@ -481,15 +491,20 @@ some methods but not others. Partial mocks are widely considered to be an anti-p
481
491
#### Spy
482
492
Records every invocation made against it and can verify certain interactions took place after the fact.
483
493
484
-
## Internationalization
485
-
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.
486
-
487
494
## Tips
488
495
1. Make test fail at least once to make sure it was a meaningful test
489
496
2. "If you or another developer change the component in a way that it changes its behaviour at least one test should fail." - [How to Unit Test in React](https://itnext.io/how-to-unit-test-in-react-72e911e2b8d)
490
497
3. Avoid using numbers or data that seem "special" in your tests. For example, if you were checking the "age" variable in a component is a integer, but checked it as so ``expect(person.ageValidator(18)).toBe(true)``, the reader might assume that the number 18 had some significance to the function because it's a significant age. It would be better to have used 1234.
491
498
4. Tests should help other developers understand the expected behavior of the component that it's testing
492
499
500
+
## Files to start with
501
+
502
+
These files still need tests! If you want to contribute by writing tests, please consider starting with these:
0 commit comments