enyzme: update

This commit is contained in:
Rico Sta. Cruz 2017-09-14 18:03:54 +08:00
parent c907827c27
commit 3418cd1aaa
No known key found for this signature in database
GPG Key ID: CAAD38AE2962619A
1 changed files with 51 additions and 11 deletions

View File

@ -6,18 +6,56 @@ updated: 2017-09-14
weight: -1 weight: -1
--- ---
## Getting started
{: .-three-column}
### Moutning
{: .-prime}
```js
import {shallow, mount} from 'enzyme'
```
{: .-setup}
```js
wrap = shallow(<MyComponent />)
```
```js
wrap = mount(<MyComponent />)
```
Shallow wrapping doesn't descend down to sub-components.
A full mount also mounts sub-components.
See: [Shallow rendering](http://airbnb.io/enzyme/docs/api/shallow.html),
[Full rendering](http://airbnb.io/enzyme/docs/api/mount.html)
### Jest
```js
import toJson from 'enzyme-to-json'
```
{: .-setup}
```js
it('works', () => {
wrap = mount(<MyComponent />)
expect(toJson(wrap)).toMatchSnapshot()
})
```
Converts an Enzyme wrapper to a format compatible with Jest snapshots. See: [enzyme-to-json](https://www.npmjs.com/package/enzyme-to-json)
### Debugging
```js
console.log(wrap.debug())
```
Shows HTML for debugging purposes. See: [debug()](http://airbnb.io/enzyme/docs/api/ReactWrapper/debug.html)
## ReactWrapper ## ReactWrapper
### ReactWrapper
```js
wrap = shallow(<MyComponent />) // => ReactWrapper (shallow)
```
```js
wrap = mount(<MyComponent />) // => ReactWrapper (full)
```
### Traversing ### Traversing
```js ```js
@ -40,6 +78,8 @@ wrap.getNodes() // => Array<ReactElement>
wrap.getDOMNode() // => DOMComponent wrap.getDOMNode() // => DOMComponent
``` ```
See: [Full rendering API](http://airbnb.io/enzyme/docs/api/mount.html)
### Actions ### Actions
```js ```js
@ -89,4 +129,4 @@ wrap.containsAnyMatchingElements([ <div /> ]) // => boolean
## References ## References
- <https://github.com/airbnb/enzyme/blob/master/docs/api/mount.md> - <https://airbnb.io/enzyme>