-
Notifications
You must be signed in to change notification settings - Fork 322
Translate Shallow renderer #32
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
Merged
glaucia86
merged 3 commits into
reactjs:master
from
henriquejensen:shallow-renderer-translation
Feb 10, 2019
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,69 @@ | ||
--- | ||
id: shallow-renderer | ||
title: Shallow Renderer | ||
title: Renderização superficial (Shallow Renderer) | ||
permalink: docs/shallow-renderer.html | ||
layout: docs | ||
category: Reference | ||
--- | ||
|
||
**Importing** | ||
**Importando** | ||
|
||
```javascript | ||
import ShallowRenderer from 'react-test-renderer/shallow'; // ES6 | ||
var ShallowRenderer = require('react-test-renderer/shallow'); // ES5 with npm | ||
var ShallowRenderer = require('react-test-renderer/shallow'); // ES5 com npm | ||
``` | ||
|
||
## Overview {#overview} | ||
## Visão geral {#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. | ||
Ao escrever testes unitários para o React, a renderização superficial pode ser útil. A renderização superficial o deixa renderizar um componente a um "nível simples de profundidade" e afirmar fatos sobre o que este método retorna, sem se preocupar sobre o comportamento dos componentes filhos, os quais não são instanciados ou renderizados. Isto não requer o DOM. | ||
tibuurcio marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
For example, if you have the following component: | ||
Por exemplo, se você tem o seguinte componente: | ||
|
||
```javascript | ||
function MyComponent() { | ||
return ( | ||
<div> | ||
<span className="heading">Title</span> | ||
<span className="heading">Título</span> | ||
<Subcomponent foo="bar" /> | ||
</div> | ||
); | ||
} | ||
``` | ||
|
||
Then you can assert: | ||
Então pode afirmar: | ||
tibuurcio marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```javascript | ||
import ShallowRenderer from 'react-test-renderer/shallow'; | ||
|
||
// in your test: | ||
// no seu teste: | ||
const renderer = new ShallowRenderer(); | ||
renderer.render(<MyComponent />); | ||
const result = renderer.getRenderOutput(); | ||
|
||
expect(result.type).toBe('div'); | ||
expect(result.props.children).toEqual([ | ||
<span className="heading">Title</span>, | ||
<span className="heading">Título</span>, | ||
<Subcomponent foo="bar" /> | ||
]); | ||
``` | ||
|
||
Shallow testing currently has some limitations, namely not supporting refs. | ||
O teste superficial atualmente tem algumas limitações, ou seja, não suporta refs. | ||
|
||
> Note: | ||
> Nota: | ||
> | ||
> 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. | ||
> Nós também recomendamos verificar a [Shallow Rendering API](http://airbnb.io/enzyme/docs/api/shallow.html) da Enzyme. Ela fornece uma API de alto nível mais agradável sobre a mesma funcionalidade. | ||
|
||
## Reference {#reference} | ||
## Referência {#reference} | ||
|
||
### `shallowRenderer.render()` {#shallowrendererrender} | ||
|
||
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. | ||
Você pode pensar no shallowRenderer como um "lugar" para renderizar o componente que você esta testando, e do qual irá extrair a saída do componente. | ||
|
||
`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()` é similar ao [`ReactDOM.render()`](/docs/react-dom.html#render) mas ela não requer o DOM e somente renderiza um nível simples de profundidade. Isto significa que você pode testar componentes isolados de como seus filhos são implementados. | ||
|
||
### `shallowRenderer.getRenderOutput()` {#shallowrenderergetrenderoutput} | ||
|
||
After `shallowRenderer.render()` has been called, you can use `shallowRenderer.getRenderOutput()` to get the shallowly rendered output. | ||
Depois do `shallowRenderer.render()` ter sido chamado, você pode usar `shallowRenderer.getRenderOutput()` para pegar a saída renderizada superficialmente. | ||
|
||
You can then begin to assert facts about the output. | ||
|
||
Você pode então começar a afirmar fatos sobre a saída. | ||
tibuurcio marked this conversation as resolved.
Show resolved
Hide resolved
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.