Skip to content

Commit fe2d725

Browse files
committed
moved around the "what to test" suggestions
1 parent 57d0fcf commit fe2d725

File tree

1 file changed

+16
-25
lines changed

1 file changed

+16
-25
lines changed

developer_docs/testing.md

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,20 @@ Want to get started writing a test for a new file or an existing file, but not s
7878
3. If it is, see the redux section below on how to write tests for that.
7979
4. If it's not, see the section below on writing tests for unconnected components.
8080

81+
For any type of component, you might want to consider testing:
82+
- User input results in the class's method being called.
83+
```
84+
//component is the return value of calling render()
85+
const spy1 = jest.spyOn(component.instance(), 'func1');
86+
act(() => {
87+
fireEvent.click(screen.getByTestId("testid"));
88+
});
89+
expect(spy1).toHaveBeenCalledTimes(1);
90+
```
91+
- The text or divs that you expect to be on the page are actually there.
92+
- a previously saved snapshot of the HTML matches a snapshot taken during testing.
93+
- what else?? help!
94+
8195
### For Redux action creators or reducers
8296
See the [redux section](#Testing-Redux) below :)
8397

@@ -244,10 +258,10 @@ This folder contains the inital redux states that you can provide to the ``redux
244258
245259
### jest configs in package.json
246260
247-
this i dont know much about yet but want to understand
261+
in progress
248262
249263
## Testing plain components
250-
If it doesn't contain ``connect(mapStateToProps, mapDispatchToProps)(ComponentName)`` or use hooks like ``useSelector``, then your component is not connected to Redux and testing your component will be simpler and might look something like this:
264+
If it doesn't contain ``connect(mapStateToProps, mapDispatchToProps)(ComponentName)`` or use hooks like ``useSelector``, then your component is not directly using Redux and testing your component will be simpler and might look something like this:
251265
252266
```
253267
import React from 'react';
@@ -319,17 +333,6 @@ Consider what you want to test. Some possible things might be:
319333
expect(yourMockFunction).toHaveBeenCalledTimes(1);
320334
expect(yourMockFunction.mock.calls[0][0]).toBe(argument);
321335
```
322-
- User input results in the class's method being called.
323-
```
324-
//component is the return value of calling render()
325-
const spy1 = jest.spyOn(component.instance(), 'func1');
326-
act(() => {
327-
fireEvent.click(screen.getByTestId("testid"));
328-
});
329-
expect(spy1).toHaveBeenCalledTimes(1);
330-
```
331-
- The text or divs that you expect to be on the page are actually there.
332-
- a previously saved snapshot of the HTML matches a snapshot taken during testing.
333336
- what else???? help!
334337
335338
## Testing Redux
@@ -427,18 +430,6 @@ Some things to consider testing:
427430
428431
expect(store.getActions()).toEqual(expect.arrayContaining(expectedAction));
429432
```
430-
- User input results in the class's method being called.
431-
```
432-
//component is the return value of calling render()
433-
const spy1 = jest.spyOn(component.instance(), 'func1');
434-
act(() => {
435-
fireEvent.click(screen.getByTestId("testid"));
436-
});
437-
expect(spy1).toHaveBeenCalledTimes(1);
438-
```
439-
- The text or divs that you expect to be on the page are actually there.
440-
- a previously saved snapshot of the HTML matches a snapshot taken during testing.
441-
- what else???? help!
442433
443434
## How to handle API calls in tests
444435

0 commit comments

Comments
 (0)