|
1 | 1 | ---
|
2 | 2 | id: shallow-renderer
|
3 |
| -title: Shallow Renderer |
| 3 | +title: Sekély renderelő |
4 | 4 | permalink: docs/shallow-renderer.html
|
5 | 5 | layout: docs
|
6 | 6 | category: Reference
|
7 | 7 | ---
|
8 | 8 |
|
9 |
| -**Importing** |
| 9 | +**Importálás** |
10 | 10 |
|
11 | 11 | ```javascript
|
12 | 12 | import ShallowRenderer from 'react-test-renderer/shallow'; // ES6
|
13 | 13 | var ShallowRenderer = require('react-test-renderer/shallow'); // ES5 with npm
|
14 | 14 | ```
|
15 | 15 |
|
16 |
| -## Overview {#overview} |
| 16 | +## Áttekintés {#overview} |
17 | 17 |
|
18 |
| -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. |
| 18 | +Amikor egységteszteket írsz Reacthez, a sekély renderelés hasznos lehet. A sekély renderelés lehetővé teszi egy komponens renderelését "egy szint mélységig", és tényeket tudsz megerősíteni arról, hogy a render metódus mit ad vissza anélkül, hogy a gyermekkomponensek viselkedésétől kéne aggódnod, amik nem lesznek renderelve. Ez nem igényel DOM-ot. |
19 | 19 |
|
20 |
| -For example, if you have the following component: |
| 20 | +Például ha van ez a komponensed: |
21 | 21 |
|
22 | 22 | ```javascript
|
23 | 23 | function MyComponent() {
|
24 | 24 | return (
|
25 | 25 | <div>
|
26 |
| - <span className="heading">Title</span> |
| 26 | + <span className="heading">Cím</span> |
27 | 27 | <Subcomponent foo="bar" />
|
28 | 28 | </div>
|
29 | 29 | );
|
30 | 30 | }
|
31 | 31 | ```
|
32 | 32 |
|
33 |
| -Then you can assert: |
| 33 | +Akkor az alábbit állíthatod: |
34 | 34 |
|
35 | 35 | ```javascript
|
36 | 36 | import ShallowRenderer from 'react-test-renderer/shallow';
|
37 | 37 |
|
38 |
| -// in your test: |
| 38 | +// a tesztedben: |
39 | 39 | const renderer = new ShallowRenderer();
|
40 | 40 | renderer.render(<MyComponent />);
|
41 | 41 | const result = renderer.getRenderOutput();
|
42 | 42 |
|
43 | 43 | expect(result.type).toBe('div');
|
44 | 44 | expect(result.props.children).toEqual([
|
45 |
| - <span className="heading">Title</span>, |
| 45 | + <span className="heading">Cím</span>, |
46 | 46 | <Subcomponent foo="bar" />
|
47 | 47 | ]);
|
48 | 48 | ```
|
49 | 49 |
|
50 |
| -Shallow testing currently has some limitations, namely not supporting refs. |
| 50 | +A sekély renderelésnek jelnelg vannak korlátai, ugyanis nem támogatja a ref-eket. |
51 | 51 |
|
52 |
| -> Note: |
| 52 | +> Megjegyzés: |
53 | 53 | >
|
54 |
| -> 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. |
| 54 | +> Ajánljuk továbbá, hogy nézz rá az Enzyme [Shallow Rendering API](https://airbnb.io/enzyme/docs/api/shallow.html)-jára. Ez szebb, felsőbb-szintű API-ket szolgáltat ugyanazzal a funkcionalitással. |
55 | 55 |
|
56 |
| -## Reference {#reference} |
| 56 | +## Referencia {#reference} |
57 | 57 |
|
58 | 58 | ### `shallowRenderer.render()` {#shallowrendererrender}
|
59 | 59 |
|
60 |
| -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. |
| 60 | +Gondolhatsz úgy a shallowRenderer-re, mint egy "helyre", ahova a tesztelt komponenst renderelheted és ahonnan ki tudod vonni a komponens kimenetét. |
61 | 61 |
|
62 |
| -`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. |
| 62 | +A `shallowRenderer.render()` hasonló a [`ReactDOM.render()`](/docs/react-dom.html#render)-hez, de nincs szüksége DOM-ra, és csak csak egy szint mélységig renderel. Ez azt jelenti, hogy a komponenseket elzártan tudod tesztelni a gyermekeik implementációjától. |
63 | 63 |
|
64 | 64 | ### `shallowRenderer.getRenderOutput()` {#shallowrenderergetrenderoutput}
|
65 | 65 |
|
66 |
| -After `shallowRenderer.render()` has been called, you can use `shallowRenderer.getRenderOutput()` to get the shallowly rendered output. |
| 66 | +A `shallowRenderer.render()` meghívása után használhatod a `shallowRenderer.getRenderOutput()` metódust, hogy megkapd a sekélyen renderelt kimenetet. |
67 | 67 |
|
68 |
| -You can then begin to assert facts about the output. |
| 68 | +Ezután nekiálhatsz tényeket megerősíteni a kimenetről. |
0 commit comments