Skip to content
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

docs(cn): translate content/docs/addons-shallow-renderer.md into Chinese #91

Merged

Conversation

Ryanhui
Copy link
Contributor

@Ryanhui Ryanhui commented Feb 12, 2019

No description provided.

@Ryanhui Ryanhui changed the title docs(cn): translate content/docs/reference-javascript-environment-requirements.md into Chinese docs(cn): translate content/docs/addons-shallow-renderer.md into Chinese Feb 12, 2019
@QC-L QC-L added the Pending Review 已翻译,待校对阶段 label Feb 12, 2019
Copy link
Member

@yuqingc yuqingc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“您” -> "你"

@netlify
Copy link

netlify bot commented Feb 13, 2019

Deploy preview for cn-reactjs ready!

Built with commit 8b7489b

https://deploy-preview-91--cn-reactjs.netlify.com

@QC-L QC-L mentioned this pull request Feb 14, 2019
Copy link
Contributor

@yhsunshining yhsunshining left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!
基本没什么问题,有一点点小的格式需要修改下~

React 16 depends on the collection types [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) and [Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set). If you support older browsers and devices which may not yet provide these natively (e.g. IE < 11) or which have non-compliant implementations (e.g. IE 11), consider including a global polyfill in your bundled application, such as [core-js](https://github.com/zloirock/core-js) or [babel-polyfill](https://babeljs.io/docs/usage/polyfill/).

A polyfilled environment for React 16 using core-js to support older browsers might look like:
React 16 依赖集合类型 [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) 和 [Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)。如果你要支持没有原生提供这些能力的老的浏览器或者设备(例如 IE < 11)或者不符合规范实现的(例如 IE 11),考虑在你的应用库中包含一个全局的 polyfill ,例如[core-js](https://github.com/zloirock/core-js) 或 [babel-polyfill](https://babeljs.io/docs/usage/polyfill/)。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

少了个空格

Suggested change
React 16 依赖集合类型 [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)[Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)。如果你要支持没有原生提供这些能力的老的浏览器或者设备(例如 IE < 11)或者不符合规范实现的(例如 IE 11),考虑在你的应用库中包含一个全局的 polyfill ,例如[core-js](https://github.com/zloirock/core-js)[babel-polyfill](https://babeljs.io/docs/usage/polyfill/)
React 16 依赖集合类型 [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)[Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)。如果你要支持没有原生提供这些能力的老的浏览器或者设备(例如 IE < 11)或者不符合规范实现的(例如 IE 11),考虑在你的应用库中包含一个全局的 polyfill ,例如 [core-js](https://github.com/zloirock/core-js)[babel-polyfill](https://babeljs.io/docs/usage/polyfill/)


> Note:
> 注意:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

全角标点

Suggested change
> 注意:
> 注意


`shallowRenderer.render()` is similar to [`ReactDOM.render()`](/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.render()` [`ReactDOM.render()`](/docs/react-dom.html#render) 很像,但是它不需要 DOM 并且只渲染一层。 这意味着你可以只测试组件,不必担心它的子组件是如何实现的。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`shallowRenderer.render()`[`ReactDOM.render()`](/docs/react-dom.html#render) 很像,但是它不需要 DOM 并且只渲染一层。 这意味着你可以只测试组件,不必担心它的子组件是如何实现的
`shallowRenderer.render()`[`ReactDOM.render()`](/docs/react-dom.html#render) 很像,但是它不需要 DOM 并且只渲染一层。 这意味着你可以只测试组件,不必关心它的子组件是如何实现的

或者,这里需要直译吗?

@netlify
Copy link

netlify bot commented Feb 24, 2019

Deploy preview for zh-hans-reactjs ready!

Built with commit 8b7489b

https://deploy-preview-91--zh-hans-reactjs.netlify.com


一个使用 core-js 支持老版浏览器的 React 16 的 polyfill 环境大致如下:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

该行下应该有一个空行


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

## Overview {#overview}
## 概述 {#overview}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## 概述 {#overview}
## 概览 {#overview}


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.
当为 React 写单元测试时,浅层渲染十分有用。浅层渲染可以使你只渲染一个组件的“第一层”,并且对组件的 render 方法的返回值进行断言,不用担心子组件的行为,子组件并没有实例化或被渲染。并且浅层渲染不需要 DOM
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
当为 React 写单元测试时,浅层渲染十分有用。浅层渲染可以使你只渲染一个组件的“第一层”,并且对组件的 render 方法的返回值进行断言,不用担心子组件的行为,子组件并没有实例化或被渲染。并且浅层渲染不需要 DOM。
当为 React 编写单元测试时,浅层渲染十分有用。浅层渲染可以只渲染组件的“第一层”,并且对组件的 render 方法的返回值进行断言,不必担心子组件的行为,子组件并没有实例化或被渲染。并且浅层渲染不依赖 DOM。

@@ -30,12 +30,12 @@ function MyComponent() {
}
```

Then you can assert:
你可以断言(assert):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
你可以断言(assert):
你可以使用断言(assert):


```javascript
import ShallowRenderer from 'react-test-renderer/shallow';

// in your test:
// 在你的测试中:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 在你的测试中:
// 测试代码:

@@ -47,22 +47,22 @@ expect(result.props.children).toEqual([
]);
```

Shallow testing currently has some limitations, namely not supporting refs.
浅层测试(Shallow testing)当前还有一些局限,即不支持 refs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
浅层测试(Shallow testing)当前还有一些局限,即不支持 refs。
浅层测试(Shallow testing)目前有些局限性,即不支持 refs。


`shallowRenderer.render()` is similar to [`ReactDOM.render()`](/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.render()` [`ReactDOM.render()`](/docs/react-dom.html#render) 很像,但是它不需要 DOM 并且只渲染一层。 这意味着你可以只测试组件,不必关心它的子组件是如何实现的。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`shallowRenderer.render()`[`ReactDOM.render()`](/docs/react-dom.html#render) 很像,但是它不需要 DOM 并且只渲染一层。 这意味着你可以只测试组件,不必关心它的子组件是如何实现的
`shallowRenderer.render()`[`ReactDOM.render()`](/docs/react-dom.html#render) 很像,但是它不依赖 DOM 且只渲染一层。这意味着你可以对组件和其子组件的实现进行隔离测试


### `shallowRenderer.getRenderOutput()` {#shallowrenderergetrenderoutput}

After `shallowRenderer.render()` has been called, you can use `shallowRenderer.getRenderOutput()` to get the shallowly rendered output.
`shallowRenderer.render()` 被调用后,你可以使用 `shallowRenderer.getRenderOutput()` 来获取浅层渲染的输出。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`shallowRenderer.render()` 被调用后,你可以使用 `shallowRenderer.getRenderOutput()` 来获取浅层渲染的输出
`shallowRenderer.render()` 被调用后,你可以使用 `shallowRenderer.getRenderOutput()` 来获取浅层渲染的输出内容


You can then begin to assert facts about the output.
然后,你就可以开始对输出进行断言(assert)了。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
然后,你就可以开始对输出进行断言(assert)了。
接着,你就可以开始对输出内容进行断言(assert)了。

@@ -23,8 +23,8 @@ ReactDOM.render(
);
```

React also depends on `requestAnimationFrame` (even in test environments).
You can use the [raf](https://www.npmjs.com/package/raf) package to shim `requestAnimationFrame`:
React 也依赖于 requestAnimationFrame(甚至包括测试环境)。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
React 也依赖于 requestAnimationFrame(甚至包括测试环境)。
React 同时还依赖于 requestAnimationFrame(甚至包括测试环境)。

React also depends on `requestAnimationFrame` (even in test environments).
You can use the [raf](https://www.npmjs.com/package/raf) package to shim `requestAnimationFrame`:
React 也依赖于 requestAnimationFrame(甚至包括测试环境)。
你可以使用 [raf](https://www.npmjs.com/package/raf) 包增添 `requestAnimationFrame`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
你可以使用 [raf](https://www.npmjs.com/package/raf) 包增添 `requestAnimationFrame`
你可以使用 [raf](https://www.npmjs.com/package/raf) 的 package 添加 `requestAnimationFrame` 的 shim

QC-L
QC-L previously approved these changes Mar 6, 2019
@QC-L QC-L added Pending Re-Review 已修改,待审校阶段 and removed Pending Review 已翻译,待校对阶段 labels Mar 6, 2019
hijiangtao
hijiangtao previously approved these changes Mar 7, 2019
Copy link
Member

@hijiangtao hijiangtao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -30,12 +30,12 @@ function MyComponent() {
}
```

Then you can assert:
你可以使用断言(assert):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

断言需要括号注明么?这在测试框架中是一个非常常见的术语

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加到术语表里,这里忽略?

@QC-L QC-L dismissed stale reviews from hijiangtao and themself via e7f64ac March 7, 2019 02:06
@hijiangtao hijiangtao merged commit 74715d6 into reactjs:master Mar 7, 2019
OhIAmFine pushed a commit to OhIAmFine/zh-hans.reactjs.org that referenced this pull request May 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Pending Re-Review 已修改,待审校阶段
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants