-
Notifications
You must be signed in to change notification settings - Fork 47k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
All doc updates forv15.5 #9359
All doc updates forv15.5 #9359
Changes from all commits
8dd97f8
5e9e393
c34ae0d
cb209f1
21f7c87
33715f3
130cd72
a5b71c3
d543ebd
95b3204
38b766e
7116b56
afc313d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
--- | ||
id: shallow-renderer | ||
title: Shallow Renderer | ||
permalink: docs/shallow-renderer.html | ||
layout: docs | ||
category: Reference | ||
--- | ||
|
||
**Importing** | ||
|
||
```javascript | ||
import ReactShallowRenderer from 'react-test-renderer/shallow'; // ES6 | ||
var ReactShallowRenderer = require('react-test-renderer/shallow'); // ES5 with npm | ||
``` | ||
### Shallow Rendering | ||
|
||
Shallow rendering lets you render a component "one level deep" and assert facts about what its render method returns, without worrying about the behavior of child components, which are not instantiated or rendered. This does not require a DOM. | ||
|
||
- [`shallowRenderer.render()`](#shallowrenderer.render) | ||
- [`shallowRenderer.getRenderOutput()`](#shallowrenderer.getrenderoutput) | ||
|
||
You can think of the shallowRenderer as a "place" to render the component you're testing, and from which you can extract the component's output. | ||
|
||
[`shallowRenderer.render()`](#shallowrenderer.render) is similar to [`ReactDOM.render()`](/react/docs/react-dom.html#render) but it doesn't require DOM and only renders a single level deep. This means you can test components isolated from how their children are implemented. | ||
|
||
After `shallowRenderer.render()` has been called, you can use [`shallowRenderer.getRenderOutput()`](#shallowrenderer.getrenderoutput) to get the shallowly rendered output. | ||
|
||
You can then begin to assert facts about the output. For example, if you have the following component: | ||
|
||
```javascript | ||
function MyComponent() { | ||
return ( | ||
<div> | ||
<span className="heading">Title</span> | ||
<Subcomponent foo="bar" /> | ||
</div> | ||
); | ||
} | ||
``` | ||
|
||
Then you can assert: | ||
|
||
```javascript | ||
const ReactShallowRenderer = require('react-test-renderer/shallow'); | ||
const shallowRenderer = new ReactShallowRenderer(); | ||
shallowRenderer.render(<MyComponent />); | ||
const result = shallowRenderer.getRenderOutput(); | ||
|
||
expect(result.type).toBe('div'); | ||
expect(result.props.children).toEqual([ | ||
<span className="heading">Title</span>, | ||
<Subcomponent foo="bar" /> | ||
]); | ||
``` | ||
|
||
Shallow testing currently has some limitations, namely not supporting refs. | ||
|
||
We also recommend checking out Enzyme's [Shallow Rendering API](http://airbnb.io/enzyme/docs/api/shallow.html). It provides a nicer higher-level API over the same functionality. | ||
|
||
* * * |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,8 +12,6 @@ redirect_from: | |
- "docs/transferring-props-zh-CN.html" | ||
- "tips/props-in-getInitialState-as-anti-pattern.html" | ||
- "tips/communicate-between-components.html" | ||
prev: rendering-elements.html | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did we remove these? Their ordering seemed important to me. |
||
next: state-and-lifecycle.html | ||
--- | ||
|
||
Components let you split the UI into independent, reusable pieces, and think about each piece in isolation. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,6 @@ id: composition-vs-inheritance | |
title: Composition vs Inheritance | ||
permalink: docs/composition-vs-inheritance.html | ||
redirect_from: "docs/multiple-components.html" | ||
prev: lifting-state-up.html | ||
next: thinking-in-react.html | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question here. |
||
--- | ||
|
||
React has a powerful composition model, and we recommend using composition instead of inheritance to reuse code between components. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,6 @@ | |
id: conditional-rendering | ||
title: Conditional Rendering | ||
permalink: docs/conditional-rendering.html | ||
prev: handling-events.html | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My thought was that they are no longer part of an ordered navigation - each one is now either a stand-alone package, or deprecated. They soon won't live in the main React documentation. The 'next' and 'prev' links only make sense when they are all part of the set of 'addons', but the concept of the set itself is deprecated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm. I'm a bit confused. These pages (e.g. Conditional Rendering) don't have to do with addons as far as I can see. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right - I was just going through the list of add-ons docs and accidentally updated some others too. Thanks! Fixing in that follow-up PR. |
||
next: lists-and-keys.html | ||
redirect_from: "tips/false-in-jsx.html" | ||
--- | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to change snippet below to match package name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! Will submit a follow-up PR.