Skip to content

Commit

Permalink
Fix doc styling and formatting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Jun 9, 2017
1 parent a8d5b2b commit 107d622
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 25 deletions.
3 changes: 1 addition & 2 deletions docs/_posts/2015-12-16-ismounted-antipattern.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,5 @@ const makeCancelable = (promise) => {
};
};
```
As an added bonus for getting your code cleaned up early, getting rid of `isMounted()` makes it one step easier for you to upgrade to ES6 classes, where using `isMounted()` is already prohibited. Happy coding!

* _Update 2017-05-12: altered `#makeCancelable` implementation so rejected promises won't go uncaught._
As an added bonus for getting your code cleaned up early, getting rid of `isMounted()` makes it one step easier for you to upgrade to ES6 classes, where using `isMounted()` is already prohibited. Happy coding!
5 changes: 3 additions & 2 deletions docs/docs/addons-animation.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ redirect_from:
- "docs/animation-zh-CN.html"
---

>Note:
> `ReactTransitionGroup` and `ReactCSSTransitionGroup` are both deprecated as of React v15.5.0. The recommendation is to use `TransitionGroup` and `CSSTransitionGroup` from ['react-transition-group'](https://github.com/reactjs/react-transition-group) instead.
> Note:
>
> `ReactTransitionGroup` and `ReactCSSTransitionGroup` are both deprecated as of React v15.5.0. The recommendation is to use `TransitionGroup` and `CSSTransitionGroup` from [`react-transition-group`](https://github.com/reactjs/react-transition-group) instead.
The [`ReactTransitionGroup`](#low-level-api-reacttransitiongroup) add-on component is a low-level API for animation, and [`ReactCSSTransitionGroup`](#high-level-api-reactcsstransitiongroup) is an add-on component for easily implementing basic CSS animations and transitions.

Expand Down
1 change: 1 addition & 0 deletions docs/docs/addons-pure-render-mixin.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ category: Add-Ons
---

> Note:
>
> `PureRenderMixin` is a legacy add-on. Use [`React.PureComponent`](/react/docs/react-api.html#react.purecomponent) instead.
**Importing**
Expand Down
1 change: 1 addition & 0 deletions docs/docs/addons-shallow-compare.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ category: Reference
---

> Note:
>
> `shallowCompare` is a legacy add-on. Use [`React.PureComponent`](/react/docs/react-api.html#react.purecomponent) instead.
**Importing**
Expand Down
45 changes: 27 additions & 18 deletions docs/docs/addons-shallow-renderer.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,15 @@ category: Reference
**Importing**

```javascript
import ReactShallowRenderer from 'react-test-renderer/shallow'; // ES6
var ReactShallowRenderer = require('react-test-renderer/shallow'); // ES5 with npm
import ShallowRenderer from 'react-test-renderer/shallow'; // ES6
var ShallowRenderer = require('react-test-renderer/shallow'); // ES5 with npm
```
### Shallow Rendering

When writing unit tests for React, shallow rendering can be helpful. 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.
## Overview

[`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.
When writing unit tests for React, shallow rendering can be helpful. 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.

You can then begin to assert facts about the output. For example, if you have the following component:
For example, if you have the following component:

```javascript
function MyComponent() {
Expand All @@ -41,10 +33,12 @@ function MyComponent() {
Then you can assert:

```javascript
const ReactShallowRenderer = require('react-test-renderer/shallow');
const shallowRenderer = new ReactShallowRenderer();
shallowRenderer.render(<MyComponent />);
const result = shallowRenderer.getRenderOutput();
import ShallowRenderer from 'react-test-renderer/shallow';

// in your test:
const renderer = new ShallowRenderer();
renderer.render(<MyComponent />);
const result = renderer.getRenderOutput();

expect(result.type).toBe('div');
expect(result.props.children).toEqual([
Expand All @@ -55,5 +49,20 @@ expect(result.props.children).toEqual([

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.
> Note:
>
> 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.
## Reference

### `shallowRenderer.render()`

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()` 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.

### `shallowRenderer.getRenderOutput()`

After `shallowRenderer.render()` has been called, you can use `shallowRenderer.getRenderOutput()` to get the shallowly rendered output.

You can then begin to assert facts about the output.
8 changes: 7 additions & 1 deletion docs/docs/addons-test-utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,14 @@ var ReactTestUtils = require('react-dom/test-utils'); // ES5 with npm

## Shallow Rendering

When writing unit tests for React, shallow rendering can be helpful. 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.

> Note:
> The shallow renderer has moved to `react-test-renderer/shallow`. [Please see the updated documentation.](/react/docs/shallow-renderer.html)
>
> The shallow renderer has moved to `react-test-renderer/shallow`.<br>
> [Learn more about shallow rendering on its reference page.](/react/docs/shallow-renderer.html)
## Other Utilities

### `Simulate`

Expand Down
1 change: 1 addition & 0 deletions docs/docs/addons-two-way-binding-helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ category: Add-Ons
---

> Note:
>
> `LinkedStateMixin` is deprecated as of React v15. The recommendation is to explicitly set the value and change handler, instead of using `LinkedStateMixin`.
**Importing**
Expand Down
3 changes: 2 additions & 1 deletion docs/docs/addons-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ category: Add-Ons
---

> Note:
> `update` is a legacy add-on. Use [kolodny/immutability-helper](https://github.com/kolodny/immutability-helper) instead.
>
> `update` is a legacy add-on. Use [`immutability-helper`](https://github.com/kolodny/immutability-helper) instead.
**Importing**

Expand Down
4 changes: 3 additions & 1 deletion docs/docs/lifting-state-up.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ Now, when the `TemperatureInput` wants to update its temperature, it calls `this
this.props.onTemperatureChange(e.target.value);
```

> Note that there is no special meaning to either `temperature` or `onTemperatureChange` prop names in custom components. We could have called them anything else, like name them `value` and `onChange` which is a common convention.
>Note:
>
>There is no special meaning to either `temperature` or `onTemperatureChange` prop names in custom components. We could have called them anything else, like name them `value` and `onChange` which is a common convention.
The `onTemperatureChange` prop will be provided together with the `temperature` prop by the parent `Calculator` component. It will handle the change by modifying its own local state, thus re-rendering both inputs with the new values. We will look at the new `Calculator` implementation very soon.

Expand Down

0 comments on commit 107d622

Please sign in to comment.