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
14
14
```
15
15
16
-
## Overview
16
+
## Resumen
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
+
Este paquete proporciona un procesador de React que se puede usar para procesar componentes de React a objetos JavaScript puros, sin depender del DOM o de un entorno móvil nativo.
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
+
Básicamente, este paquete facilita tomar una instantánea de la jerarquía de la vista de la plataforma (similar a un árbol DOM) representada por un componente React DOM o React Nativo sin usar un navegador o[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](http://facebook.github.io/jest/blog/2016/07/27/jest-14.html).
41
+
Puede usar la función de pruebas de instantánea (`snapshot`) de Jest para guardar automáticamente una copia del árbol JSON en un archivo y comprobar en sus pruebas que no ha cambiado: [Aprende más sobre ello](http://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
+
También puede recorrer la salida para encontrar nodos específicos y hacer afirmaciones sobre ellos.
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
+
Crea una instancia `TestRenderer`con el elemento React pasado como argumento. No utiliza el DOM real, pero aún así representa completamente el árbol de componentes en memoria para que puedas hacer afirmaciones al respecto. La instancia devuelta tiene los siguientes métodos y propiedades.
106
106
107
107
### `testRenderer.toJSON()`
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](http://facebook.github.io/jest/docs/en/snapshot-testing.html#snapshot-testing-with-jest).
113
+
Devuelve un objeto que representa el árbol renderizado en formato `JSON`. Este árbol solo contiene los nodos específicos de la plataforma como `<div>`o`<View>`y sus `props`, pero no contiene ningún componente escrito por el usuario. Esta representación es práctica para usarla en [pruebas de instantanea (`snapshot`)](http://facebook.github.io/jest/docs/en/snapshot-testing.html#snapshot-testing-with-jest).
114
114
115
115
### `testRenderer.toTree()`
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
+
Devuelve un objeto que representa el árbol renderizado. A diferencia de `toJSON()`, la representación es más detallada, e incluye los componentes escritos por el usuario. Probablemente no necesites de este método al menos que estes escribiendo tu propia biblioteca de afirmaciones sobre el renderizador de prueba.
122
122
123
123
### `testRenderer.update()`
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
+
Re-renderiza el nuevo árbol en memoria con un nuevo elemento raíz. Esto simula una actualización de React en la raíz. Si el nuevo elemento posee el mismo tipo y `key` del elemento anterior, el árbol será actualizado, de lo contrario se re-montara un nuevo árbol.
130
130
131
131
### `testRenderer.unmount()`
132
132
133
133
```javascript
134
134
testRenderer.unmount()
135
135
```
136
136
137
-
Unmount the in-memory tree, triggering the appropriate lifecycle events.
137
+
Desmonta el árbol en memoria, generando los eventos apropiados del ciclo de vida.
138
138
139
139
### `testRenderer.getInstance()`
140
140
141
141
```javascript
142
142
testRenderer.getInstance()
143
143
```
144
144
145
-
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
+
Devuelve la instancia correspondiente a la raíz del elemento, si está disponible. Este método no funciona si el elemento raíz es un componente funcional, ya que los mismos no poseen instancias.
146
146
147
147
### `testRenderer.root`
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
+
Devuelve el objeto `test instance` de la raíz, el cual es útil para realizar afirmaciones acerca de nodos específicos en el árbol. Este puede ser usado para buscar otros objetos `test instance` ubicados más profundo en el árbol del componente.
154
154
155
155
### `testInstance.find()`
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
+
Busca un único objeto `test instance` descendiente para el cual `test(testInstance)`devuelve`true`. Si`test(testInstance)`no devuelve `true`para exactamente una sola instancia, entonces genera un error.
162
162
163
163
### `testInstance.findByType()`
164
164
165
165
```javascript
166
166
testInstance.findByType(type)
167
167
```
168
168
169
-
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
+
Busca un único objeto `test instance` descendiente con el`type` pasado como argumento. Si no existe un único descendiente con el tipo provisto genera un error.
170
170
171
171
### `testInstance.findByProps()`
172
172
173
173
```javascript
174
174
testInstance.findByProps(props)
175
175
```
176
176
177
-
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
+
Busca un único objeto `test instance` descendiente con los`props` pasados como argumento. Si no existe un único descendiente con los`props` genera un error.
178
178
179
179
### `testInstance.findAll()`
180
180
181
181
```javascript
182
182
testInstance.findAll(test)
183
183
```
184
184
185
-
Find all descendant test instances for which `test(testInstance)`returns`true`.
185
+
Busca todos los objetos `test instance` descendientes para los cuales `test(testInstance)`devuelve`true`.
186
186
187
187
### `testInstance.findAllByType()`
188
188
189
189
```javascript
190
190
testInstance.findAllByType(type)
191
191
```
192
192
193
-
Find all descendant test instances with the provided `type`.
193
+
Busca todos los objetos `test instance` descendientes con el tipo (`type`) pasado como argumento.
194
194
195
195
### `testInstance.findAllByProps()`
196
196
197
197
```javascript
198
198
testInstance.findAllByProps(props)
199
199
```
200
200
201
+
202
+
Busca todos los objetos `test instance` descendientes con los `props` pasados como argumento.
201
203
Find all descendant test instances with the provided `props`.
202
204
203
205
### `testInstance.instance`
@@ -206,45 +208,43 @@ Find all descendant test instances with the provided `props`.
206
208
testInstance.instance
207
209
```
208
210
209
-
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.
211
+
La instancia de componente correspondiente a este objeto `test instance`. Está únicamente disponible para componentes de clase, ya que los componentes funcionales no poseen instancias. Es equivalente al valor de `this`dentro del componente.
210
212
211
213
### `testInstance.type`
212
214
213
215
```javascript
214
216
testInstance.type
215
217
```
216
218
217
-
The component type corresponding to this test instance. For example, a `<Button />`component has a type of`Button`.
219
+
El tipo del componente que corresponde a este objeto `test instance`. Por ejemplo, un componente `<Button />`tiene un tipo`Button`.
218
220
219
221
### `testInstance.props`
220
222
221
223
```javascript
222
224
testInstance.props
223
225
```
224
226
225
-
The props corresponding to this test instance. For example, a `<Button size="small" />`component has `{size: 'small'}` as props.
227
+
Los `props` correspondientes a este objeto `test instance`. Por ejemplo, un componente `<Button size="small" />`tiene las siguientes propiedades: `{size: 'small'}`.
226
228
227
229
### `testInstance.parent`
228
230
229
231
```javascript
230
232
testInstance.parent
231
233
```
232
234
233
-
The parent test instance of this test instance.
235
+
El objeto `test instance` padre.
234
236
235
237
### `testInstance.children`
236
238
237
239
```javascript
238
240
testInstance.children
239
241
```
240
242
241
-
The children test instances of this test instance.
243
+
Los objetos `test instance` hijos directos.
242
244
243
245
## Ideas
244
246
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.
247
+
La función `TestRenderer.create` puede recibir una opción `createNodeMock` la cual permite la creación de `refs` adaptados para ser usados como objetos falsos en pruebas. `createNodeMock` acepta el elemento actual y debe retornar un objeto `ref` falso. Esto es útil cuando se necesita realizar pruebas sobre un componente que depende de `ref`
0 commit comments