jest: add react-test-renderer

This commit is contained in:
Rico Sta. Cruz 2017-09-01 05:28:18 +08:00
parent 7fe5d5ccbd
commit 61a5fed1bb
No known key found for this signature in database
GPG Key ID: CAAD38AE2962619A
2 changed files with 26 additions and 10 deletions

View File

@ -40,8 +40,8 @@
transform: translate3d(0, 1px, 0);
background: linear-gradient(
to right,
rgba($base-c, 0.05) 25%,
rgba($base-c, 0));
mix($base-c, white, 5%) 25%,
white);
}
// Line highlight ranges

32
jest.md
View File

@ -202,20 +202,36 @@ See: [Async tutorial](http://facebook.github.io/jest/docs/en/tutorial-async.html
### Snapshots
```jsx
const tree = renderer.create(
<Link page="http://www.facebook.com">Facebook</Link>
).toJSON()
it('works', () => {
const output = something()
expect(output).toMatchSnapshot()
})
```
{: data-line="3"}
First run creates a snapshot. Subsequent runs match the saved snapshot.
See: [Snapshot testing](http://facebook.github.io/jest/docs/en/snapshot-testing.html)
### React test renderer
```jsx
// First run creates a snapshot; subsequent runs match it
expect(tree).toMatchSnapshot()
import renderer from 'react-test-renderer'
```
{: .-setup}
```bash
# To update snapshots
jest --updateSnapshot
```jsx
it('works', () => {
const tree = renderer.create(
<Link page="http://www.facebook.com">Facebook</Link>
).toJSON()
expect(tree).toMatchSnapshot()
})
```
{: data-line="2,3,4"}
React's test renderer can be used for Jest snapshots.
See: [Snapshot test](http://facebook.github.io/jest/docs/en/tutorial-react-native.html#snapshot-test)
### Mocks