Skip to content

Commit 0c081c9

Browse files
committed
add to test style guide
1 parent d473ad7 commit 0c081c9

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

docs/style guide.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
For testing:
2-
- try to use .toMatchSnapshot() when possible. Note that it will NOT be possible to make use of .toMatchSnapshot for the component as a whole if 'useContext' is used within the component.
3-
- if some of the child components of the tested component uses 'useContext' then you should use ShallowRenderer from 'react-test-renderer/shallow' as follows in order to limit the Snapshot to the component itself:
2+
- try to use .toMatchSnapshot() when possible / relevant. Using asFragment will help bypass issues with useContext:
3+
```jsx
4+
it('should match DOM and render "Weight per Tier (%)", "1st place winner" etc. if bounty type is 2', () => {
5+
const { asFragment } = render(<SetTierAdminPage bounty={Constants.bounty2} />);
6+
expect(asFragment()).toMatchSnapshot();
7+
```
8+
- to shallow render and use .toMatchSnapshot() (i.e. limit the test to the component itself) you can do:
49
```jsx
10+
import ShallowRenderer from 'react-test-renderer/shallow';
511
it('should render match DOM Snapshot', () => {
612
const shallow = new ShallowRenderer();
713
shallow.render(<MyComponent />);
814
const tree = shallow.getRenderOutput();
915
expect(tree).toMatchSnapshot();
1016
});
11-
```
17+
```
1218
1319
When dispalying that could require ternaries, don't use ternaries unless its really simple.
1420
For example:

0 commit comments

Comments
 (0)