Skip to content

shallow-renderer #26

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
merged 13 commits into from
Mar 1, 2019
34 changes: 17 additions & 17 deletions content/docs/addons-shallow-renderer.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
---
id: shallow-renderer
title: Shallow Renderer
title: Поверховий рендер
permalink: docs/shallow-renderer.html
layout: docs
category: Reference
---

**Importing**
**Імпорт**

```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 з використанням npm
```

## Overview {#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. Він дозволяє відрендерити лише "один рівень глибини" компоненту і підтвердити факт того, що повертає метод рендерингу, не турбуючись про поведінку дочірніх компонентів, які не будуть створені або відрендерені. Даний процес не вимагає використання DOM.

For example, if you have the following component:
Наприклад, якщо ви маєте наступний компонент:

```javascript
function MyComponent() {
return (
<div>
<span className="heading">Title</span>
<span className="heading">Заголовок</span>
<Subcomponent foo="bar" />
</div>
);
}
```

Then you can assert:
Тоді ви можете припускати:

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

// in your test:
// У вашому тесті:
const renderer = new ShallowRenderer();
renderer.render(<MyComponent />);
const result = renderer.getRenderOutput();
Expand All @@ -47,22 +47,22 @@ expect(result.props.children).toEqual([
]);
```

Shallow testing currently has some limitations, namely not supporting refs.
Поверхове тестування наразі має деякі обмеження, а саме — немає підтримки рефів.

> Note:
> Примітка:
>
> We also recommend checking out Enzyme's [Shallow Rendering API](https://airbnb.io/enzyme/docs/api/shallow.html). It provides a nicer higher-level API over the same functionality.
> Ми також рекомендуємо використання Enzyme's [API для поверхового рендеру](https://airbnb.io/enzyme/docs/api/shallow.html) — це зручніший високорівневий API зі схожою функціональністю.

## Reference {#reference}
## Довідка {#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.
Ви можете сприймати shallowRenderer як "місце" для відображення компоненту, який ви тестуєте і з якого ви можете отримати вивід компоненту.

`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 і рендерить лише на один рівень глибини. Це означає, що ви можете проводити тестування компонентів, незалежно від реалізації дочірних компонентів.

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

After `shallowRenderer.render()` has been called, you can use `shallowRenderer.getRenderOutput()` to get the shallowly rendered output.
Ви можете побачити, що виклик `shallowRenderer.render()` повертає поверхово відрендерений вивід у `shallowRenderer.getRenderOutput()`.

You can then begin to assert facts about the output.
Потім ви можете припускати факти про формат виводу.