Skip to content

Commit d6d907d

Browse files
committed
add info about snapshot testing to style guide
1 parent 932f57d commit d6d907d

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

docs/style guide.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
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:
4+
```jsx
5+
it('should render match DOM Snapshot', () => {
6+
const shallow = new ShallowRenderer();
7+
shallow.render(<MyComponent />);
8+
const tree = shallow.getRenderOutput();
9+
expect(tree).toMatchSnapshot();
10+
});
11+
```
12+
113
When dispalying that could require ternaries, don't use ternaries unless its really simple.
214
For example:
315
```jsx

0 commit comments

Comments
 (0)