Skip to content

Commit 67576c3

Browse files
Merge pull request #37 from elyalvarado/test-renderer
Translate test renderer reference #24
2 parents 9fbe11b + b425b59 commit 67576c3

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

content/docs/reference-test-renderer.md

+31-31
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
---
22
id: test-renderer
3-
title: Test Renderer
3+
title: Renderizador de Prueba
44
permalink: docs/test-renderer.html
55
layout: docs
6-
category: Reference
6+
category: Referencia
77
---
88

9-
**Importing**
9+
**Importando**
1010

1111
```javascript
1212
import TestRenderer from 'react-test-renderer'; // ES6
1313
const TestRenderer = require('react-test-renderer'); // ES5 with npm
1414
```
1515

16-
## Overview
16+
## Resumen
1717

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.
1919

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).
2121

22-
Example:
22+
Ejemplo:
2323

2424
```javascript
2525
import TestRenderer from 'react-test-renderer';
@@ -38,9 +38,9 @@ console.log(testRenderer.toJSON());
3838
// children: [ 'Facebook' ] }
3939
```
4040

41-
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).
4242

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.
4444

4545
```javascript
4646
import TestRenderer from 'react-test-renderer';
@@ -71,7 +71,7 @@ expect(testInstance.findByProps({className: "sub"}).children).toEqual(['Sub']);
7171

7272
* [`TestRenderer.create()`](#testrenderercreate)
7373

74-
### TestRenderer instance
74+
### Instancias de TestRenderer
7575

7676
* [`testRenderer.toJSON()`](#testrenderertojson)
7777
* [`testRenderer.toTree()`](#testrenderertotree)
@@ -94,110 +94,112 @@ expect(testInstance.findByProps({className: "sub"}).children).toEqual(['Sub']);
9494
* [`testInstance.parent`](#testinstanceparent)
9595
* [`testInstance.children`](#testinstancechildren)
9696

97-
## Reference
97+
## Referencia
9898

9999
### `TestRenderer.create()`
100100

101101
```javascript
102102
TestRenderer.create(element, options);
103103
```
104104

105-
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.
106106

107107
### `testRenderer.toJSON()`
108108

109109
```javascript
110110
testRenderer.toJSON()
111111
```
112112

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).
114114

115115
### `testRenderer.toTree()`
116116

117117
```javascript
118118
testRenderer.toTree()
119119
```
120120

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.
122122

123123
### `testRenderer.update()`
124124

125125
```javascript
126126
testRenderer.update(element)
127127
```
128128

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.
130130

131131
### `testRenderer.unmount()`
132132

133133
```javascript
134134
testRenderer.unmount()
135135
```
136136

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.
138138

139139
### `testRenderer.getInstance()`
140140

141141
```javascript
142142
testRenderer.getInstance()
143143
```
144144

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.
146146

147147
### `testRenderer.root`
148148

149149
```javascript
150150
testRenderer.root
151151
```
152152

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.
154154

155155
### `testInstance.find()`
156156

157157
```javascript
158158
testInstance.find(test)
159159
```
160160

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.
162162

163163
### `testInstance.findByType()`
164164

165165
```javascript
166166
testInstance.findByType(type)
167167
```
168168

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.
170170

171171
### `testInstance.findByProps()`
172172

173173
```javascript
174174
testInstance.findByProps(props)
175175
```
176176

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.
178178

179179
### `testInstance.findAll()`
180180

181181
```javascript
182182
testInstance.findAll(test)
183183
```
184184

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`.
186186

187187
### `testInstance.findAllByType()`
188188

189189
```javascript
190190
testInstance.findAllByType(type)
191191
```
192192

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.
194194

195195
### `testInstance.findAllByProps()`
196196

197197
```javascript
198198
testInstance.findAllByProps(props)
199199
```
200200

201+
202+
Busca todos los objetos `test instance` descendientes con los `props` pasados como argumento.
201203
Find all descendant test instances with the provided `props`.
202204

203205
### `testInstance.instance`
@@ -206,45 +208,43 @@ Find all descendant test instances with the provided `props`.
206208
testInstance.instance
207209
```
208210

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.
210212

211213
### `testInstance.type`
212214

213215
```javascript
214216
testInstance.type
215217
```
216218

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`.
218220

219221
### `testInstance.props`
220222

221223
```javascript
222224
testInstance.props
223225
```
224226

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'}`.
226228

227229
### `testInstance.parent`
228230

229231
```javascript
230232
testInstance.parent
231233
```
232234

233-
The parent test instance of this test instance.
235+
El objeto `test instance` padre.
234236

235237
### `testInstance.children`
236238

237239
```javascript
238240
testInstance.children
239241
```
240242

241-
The children test instances of this test instance.
243+
Los objetos `test instance` hijos directos.
242244

243245
## Ideas
244246

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`
248248

249249
```javascript
250250
import TestRenderer from 'react-test-renderer';

0 commit comments

Comments
 (0)