From 3418cd1aaaaabd5c5fbee9e5980e026db3c28584 Mon Sep 17 00:00:00 2001 From: "Rico Sta. Cruz" Date: Thu, 14 Sep 2017 18:03:54 +0800 Subject: [PATCH] enyzme: update --- enzyme.md | 62 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 11 deletions(-) diff --git a/enzyme.md b/enzyme.md index 32f31b180..5d171ddeb 100644 --- a/enzyme.md +++ b/enzyme.md @@ -6,18 +6,56 @@ updated: 2017-09-14 weight: -1 --- +## Getting started +{: .-three-column} + +### Moutning +{: .-prime} + +```js +import {shallow, mount} from 'enzyme' +``` +{: .-setup} + +```js +wrap = shallow() +``` + +```js +wrap = mount() +``` + +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() + 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 - -```js -wrap = shallow() // => ReactWrapper (shallow) -``` - -```js -wrap = mount() // => ReactWrapper (full) -``` - ### Traversing ```js @@ -40,6 +78,8 @@ wrap.getNodes() // => Array wrap.getDOMNode() // => DOMComponent ``` +See: [Full rendering API](http://airbnb.io/enzyme/docs/api/mount.html) + ### Actions ```js @@ -89,4 +129,4 @@ wrap.containsAnyMatchingElements([
]) // => boolean ## References -- +-