You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constTestRenderer=require('react-test-renderer'); // ES5 with npm
13
+
constTestRenderer=require('react-test-renderer'); // ES5 z zainstalowanym npm
14
14
```
15
15
16
-
## Overview {#overview}
16
+
## Ogólne informacje {#overview}
17
17
18
-
This package provides a React renderer that can be used to render React components to pure JavaScript objects, without depending on the DOM or a native mobile environment.
18
+
Paczka ta udostępnia narzędzie, które renderuje komponenty reactowe do czysto javascriptowych obiektów, bez użycia drzewa DOM czy natywnego środowiska mobilnego.
19
19
20
-
Essentially, this package makes it easy to grab a snapshot of the platform view hierarchy (similar to a DOM tree) rendered by a React DOM or React Native component without using a browser or[jsdom](https://github.com/tmpvar/jsdom).
20
+
Istotą tej paczki jest łatwość wygenerowania "migawki" (ang. *snapshot*) hierarchii widoków (podobnej do drzewa DOM), wyrenderowanej przez komponent z React DOM lub React Native bez pomocy przeglądarki czy[jsdom](https://github.com/tmpvar/jsdom).
You can use Jest's snapshot testing feature to automatically save a copy of the JSON tree to a file and check in your tests that it hasn't changed: [Learn more about it](https://facebook.github.io/jest/blog/2016/07/27/jest-14.html).
41
+
Przy pomocy funkcjonalności biblioteki Jest do generowania snapshotów można automatycznie zapisać do pliku kopię drzewa w formacie JSON, a w teście sprawdzać, czy się ono nie zmieniło [(Więcej informacji na ten temat)](https://facebook.github.io/jest/blog/2016/07/27/jest-14.html).
42
42
43
-
You can also traverse the output to find specific nodes and make assertions about them.
43
+
Zwrócone drzewo można również przeszukiwać w celu znalezienia konkretnych węzłów i sprawdzenia ich właściwości.
Create a`TestRenderer`instance with the passed React element. It doesn't use the real DOM, but it still fully renders the component tree into memory so you can make assertions about it. The returned instance has the following methods and properties.
105
+
Tworzy instancję`TestRenderer`przy użyciu przekazanego elementu reactowego. Nie korzysta z prawdziwego drzewa DOM, lecz renderuje całe drzewo komponentów do pamięci, aby można było wykonać na nim asercje. Zwracana instancja posiada następujące metody i właściwości:
106
106
107
107
### `testRenderer.toJSON()` {#testrenderertojson}
108
108
109
109
```javascript
110
110
testRenderer.toJSON()
111
111
```
112
112
113
-
Return an object representing the rendered tree. This tree only contains the platform-specific nodes like`<div>`or`<View>` and their props, but doesn't contain any user-written components. This is handy for [snapshot testing](https://facebook.github.io/jest/docs/en/snapshot-testing.html#snapshot-testing-with-jest).
113
+
Zwraca obiekt reprezentujący wyrenderowane drzewo. W drzewie znajdą się wyłącznie węzły specyficzne dla platformy, np.`<div>`lub`<View>`, wraz ze swoimi właściwościami. Nie zostaną wyrenderowane natomiast żadne niestandardowe komponenty użytkownika. Funkcja przydaje się przy [testowaniu za pomocą snapshotów](https://facebook.github.io/jest/docs/en/snapshot-testing.html#snapshot-testing-with-jest).
114
114
115
115
### `testRenderer.toTree()` {#testrenderertotree}
116
116
117
117
```javascript
118
118
testRenderer.toTree()
119
119
```
120
120
121
-
Return an object representing the rendered tree. Unlike`toJSON()`, the representation is more detailed than the one provided by `toJSON()`, and includes the user-written components. You probably don't need this method unless you're writing your own assertion library on top of the test renderer.
121
+
Zwraca obiekt reprezentujący wyrenderowane drzewo. W przeciwieństwie do`toJSON()`, ta reprezentacja jest bardziej szczegółowa i zawiera również niestandardowe komponenty użytkownika. Prawdopodobnie ta funkcja nigdy ci się nie przyda, chyba że piszesz w oparciu o tę paczkę własną bibliotekę do testów.
122
122
123
123
### `testRenderer.update()` {#testrendererupdate}
124
124
125
125
```javascript
126
126
testRenderer.update(element)
127
127
```
128
128
129
-
Re-render the in-memory tree with a new root element. This simulates a React update at the root. If the new element has the same type and key as the previous element, the tree will be updated; otherwise, it will re-mount a new tree.
129
+
Przy użyciu nowego elementu głównego ponownie renderuje drzewo przechowywane w pamięci. Symuluje aktualizację przeprowadzaną przez Reacta na korzeniu drzewa. Jeśli nowy element ma ten sam typ i klucz, co poprzedni, drzewo zostanie zaktualizowane; w przeciwnym wypadku drzewo zostanie odmontowane i zamontowane ponownie.
Return the instance corresponding to the root element, if available. This will not work if the root element is a function component because they don't have instances.
145
+
Zwraca instancję korzenia drzewa, jeśli takowy istnieje. Nie zadziała, jeśli komponent główny jest funkcją, ponieważ funkcje nie mają własnych instancji.
146
146
147
147
### `testRenderer.root` {#testrendererroot}
148
148
149
149
```javascript
150
150
testRenderer.root
151
151
```
152
152
153
-
Returns the root "test instance" object that is useful for making assertions about specific nodes in the tree. You can use it to find other "test instances" deeper below.
153
+
Zwraca "instancję testową" korzenia drzewa. Przydatne do wykonywania asercji na poszczególnych węzłach drzewa, a także do wyszukiwania innych "instancji testowych" w poddrzewach.
154
154
155
155
### `testInstance.find()` {#testinstancefind}
156
156
157
157
```javascript
158
158
testInstance.find(test)
159
159
```
160
160
161
-
Find a single descendant test instance for which `test(testInstance)`returns`true`. If `test(testInstance)`does not return `true`for exactly one test instance, it will throw an error.
161
+
Wyszukuje w poddrzewie dokładnie jedną instancję testową, dla której wywołanie `test(testInstance)`zwróci`true`. Jeśli funkcja `test(testInstance)`nie zwróci `true`dla dokładnie jednej instancji, rzucony zostanie wyjątek.
Find a single descendant test instance with the provided `type`. If there is not exactly one test instance with the provided `type`, it will throw an error.
169
+
Wyszukuje w poddrzewie dokładnie jedną instancję testową o podanym typie `type`. Jeśli funkcja znajdzie inną liczbę instancji, rzucony zostanie wyjątek.
Find a single descendant test instance with the provided `props`. If there is not exactly one test instance with the provided `props`, it will throw an error.
177
+
Wyszukuje w poddrzewie dokładnie jedną instancję testową o podanych właściwościach `props`. Jeśli funkcja znajdzie inną liczbę instancji, rzucony zostanie wyjątek.
The component instance corresponding to this test instance. It is only available for class components, as function components don't have instances. It matches the `this`value inside the given component.
209
+
Zwraca instancję komponentu powiązanego z daną instancją testową. Działa tylko dla komponentów klasowych, ponieważ funkcyjne nie mają instancji. Wynik jest referencją odpowiadającą `this`w danym komponencie.
210
210
211
211
### `testInstance.type` {#testinstancetype}
212
212
213
213
```javascript
214
214
testInstance.type
215
215
```
216
216
217
-
The component type corresponding to this test instance. For example, a `<Button />`component has a type of`Button`.
217
+
Zwraca typ komponentu powiązanego z daną instancją testową. Przykładowo, typem komponentu `<Button />`jest`Button`.
218
218
219
219
### `testInstance.props` {#testinstanceprops}
220
220
221
221
```javascript
222
222
testInstance.props
223
223
```
224
224
225
-
The props corresponding to this test instance. For example, a `<Button size="small" />`component has `{size: 'small'}` as props.
The children test instances of this test instance.
241
+
Zwraca instancje potomków dla danej "instancji testowej".
242
242
243
-
## Ideas {#ideas}
243
+
## Pomysły {#ideas}
244
244
245
-
You can pass `createNodeMock` function to `TestRenderer.create` as the option, which allows for custom mock refs.
246
-
`createNodeMock`accepts the current element and should return a mock ref object.
247
-
This is useful when you test a component that relies on refs.
245
+
Do metody `TestRenderer.create` jako argument można przekazać funkcję `createNodeMock`, która pozwala na tworzenie własnych atrap referencji (ang. *mock refs*).
246
+
`createNodeMock`jako argument przyjmuje element, a zwraca obiekt będący atrapą referencji.
247
+
Przydaje się to w testach komponentów, które korzystają z referencji (ang. *refs*) do innych komponentów.
0 commit comments