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
Copy file name to clipboardExpand all lines: src/content/5/en/part5b.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -358,7 +358,7 @@ The application code can be found on [GitHub](https://github.com/fullstack-hy202
358
358
359
359
Our current implementation is quite good; it has one aspect that could be improved.
360
360
361
-
After a new note is created, it would make sense to hide the new note form. Currently, the form stays visible. There is a slight problem with hiding the form. The visibility is controlled with the <i>visible</i> state variable inside of the <i>Togglable</i> component.
361
+
After a new note is created, it would make sense to hide the new note form. Currently, the form stays visible. There is a slight problem with hiding it, the visibility is controlled with the <i>visible</i> state variable inside of the <i>Togglable</i> component.
362
362
363
363
One solution to this would be to move control of the Togglable component's state outside the component. However, we won't do that now, because we want the component to be responsible for its own state. So we have to find another solution, and find a mechanism to change the state of the component externally.
Copy file name to clipboardExpand all lines: src/content/5/en/part5c.md
+4-5Lines changed: 4 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -57,7 +57,7 @@ afterEach(() => {
57
57
})
58
58
```
59
59
60
-
Now, after each test, the function _cleanup_ is performed that resets the jsdom that is simulating the browser.
60
+
Now, after each test, the function _cleanup_ is executed to reset jsdom, which is simulating the browser.
61
61
62
62
Expand the _vite.config.js_ file as follows
63
63
@@ -131,7 +131,7 @@ We can use the object [screen](https://testing-library.com/docs/queries/about#sc
131
131
expect(element).toBeDefined()
132
132
```
133
133
134
-
The existence of an element is checked using Vitest's [expect](https://vitest.dev/api/expect.html#expect) command. Expect generates an assertion from its parameter, the validity of which can be tested using various condition functions. Now we used [toBeDefined](https://vitest.dev/api/expect.html#tobedefined) which tests whether the _element_parameter of expect exists.
134
+
The existence of an element is checked using Vitest's [expect](https://vitest.dev/api/expect.html#expect) command. Expect generates an assertion for its argument, the validity of which can be tested using various condition functions. Now we used [toBeDefined](https://vitest.dev/api/expect.html#tobedefined) which tests whether the _element_argument of expect exists.
135
135
136
136
Run the test with command _npm test_:
137
137
@@ -384,7 +384,7 @@ The expectation of the test uses [toHaveLength](https://vitest.dev/api/expect.ht
384
384
expect(mockHandler.mock.calls).toHaveLength(1)
385
385
```
386
386
387
-
The calls of the mock function are saved to the array [mock.calls](https://vitest.dev/api/mock#mock-calls) within the mock function object.
387
+
The calls to the mock function are saved to the array [mock.calls](https://vitest.dev/api/mock#mock-calls) within the mock function object.
388
388
389
389
[Mock objects and functions](https://en.wikipedia.org/wiki/Mock_object) are commonly used [stub](https://en.wikipedia.org/wiki/Method_stub) components in testing that are used for replacing dependencies of the components being tested. Mocks make it possible to return hardcoded responses, and to verify the number of times the mock functions are called and with what parameters.
The <i>beforeEach</i> formatting blog must empty the database using for example the method we used in the [material](/en/part5/end_to_end_testing#controlling-the-state-of-the-database).
1104
-
1105
1102
#### 5.18: Blog List End To End Testing, step 2
1106
1103
1107
1104
Make tests for logging in. Test both successful and unsuccessful login attempts.
@@ -1112,8 +1109,8 @@ The test structure extends like so:
The _beforeEach_ block must empty the database using, for example, the reset method we used in the [material](/en/part5/end_to_end_testing_cypress#controlling-the-state-of-the-database).
1134
+
1136
1135
<i>Optional bonus exercise</i>: Check that the notification shown with unsuccessful login is displayed red.
Copy file name to clipboardExpand all lines: src/content/5/es/part5.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ lang: es
8
8
9
9
En esta parte volvemos al frontend, primero mirando a diferentes posibilidades para probar el código React. También implementaremos la autenticación basada en tokens que permitirá a los usuarios iniciar sesión en nuestra aplicación.
Copy file name to clipboardExpand all lines: src/content/5/es/part5b.md
+15-19Lines changed: 15 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -358,9 +358,11 @@ El código de la aplicación se puede encontrar en [GitHub](https://github.com/f
358
358
359
359
Nuestra implementación actual es bastante buena, pero tiene un aspecto que podría mejorarse.
360
360
361
-
Después de crear una nueva nota, tendría sentido ocultar el nuevo formulario de nota. Actualmente, el formulario permanece visible. Hay un pequeño problema al ocultar el formulario. La visibilidad se controla con la variable <i>visible</i> dentro del componente <i>Togglable</i>. ¿Cómo podemos acceder a él fuera del componente?
361
+
Después de crear una nueva nota, tendría sentido ocultar el formulario de nueva nota. Actualmente, el formulario permanece visible. Hay un pequeño problema al ocultarlo, la visibilidad se controla con la variable <i>visible</i> dentro del componente <i>Togglable</i>.
362
362
363
-
Hay muchas formas de implementar el cierre del formulario desde el componente padre, pero usemos el mecanismo [ref](https://es.react.dev/learn/referencing-values-with-refs) de React, que ofrece una referencia al componente.
363
+
Una solución a esto sería mover el control del estado del componente Togglable fuera del componente. Sin embargo, no lo haremos ahora, porque queremos que el componente sea responsable de su propio estado. Por lo tanto, tenemos que encontrar otra solución y hallar un mecanismo para cambiar el estado del componente externamente.
364
+
365
+
Hay varias formas diferentes de implementar el acceso a las funciones de un componente desde fuera del componente, pero usemos el mecanismo de [ref](https://es.react.dev/learn/referencing-values-with-refs) de React, que ofrece una referencia al componente.
364
366
365
367
Hagamos los siguientes cambios en el componente <i>App</i>:
366
368
@@ -571,14 +573,6 @@ const Blog = ({ blog }) => {
571
573
572
574
#### 5.8: Frontend de la Lista de Blogs, paso 8
573
575
574
-
Notamos que algo está mal. Cuando se crea un nuevo blog en la aplicación, no se muestra el nombre del usuario que agregó el blog en los detalles del mismo:
575
-
576
-

577
-
578
-
Cuando se recarga el navegador, se muestra la información de la persona. Esto no es aceptable, averigua dónde está el problema y realiza la corrección necesaria.
579
-
580
-
#### 5.9: Frontend de la lista de blogs, paso 9
581
-
582
576
Implementa la funcionalidad para el botón like. Los likes aumentan al hacer un solicitud HTTP _PUT_ a la dirección única de la publicación del blog en el backend.
583
577
584
578
Dado que la operación de backend reemplaza toda la publicación del blog, deberás enviar todos sus campos en el cuerpo de la solicitud. Si deseas agregar un like a la siguiente publicación de blog:
@@ -612,7 +606,15 @@ Deberías realizar una solicitud HTTP PUT a la dirección <i>/api/blogs/5a43fde2
612
606
613
607
El Backend también debe ser actualizado para manejar la referencia al usuario.
614
608
615
-
**Una última advertencia:** si notas que estás usando async/await y el método _then_ en el mismo código, es casi seguro que estás haciendo algo mal. Usa uno u otro, y nunca uses ambos al mismo tiempo "por si acaso".
609
+
#### 5.9: Frontend de la lista de Blogs, paso 9
610
+
611
+
Nos damos cuenta de que algo está mal. Cuando se da "me gusta" a un blog en la app, el nombre del usuario que añadió el blog no se muestra en sus detalles:
612
+
613
+

614
+
615
+
Cuando se recarga el navegador, la información de la persona se muestra. Esto no es aceptable, averigua dónde está el problema y realiza la corrección necesaria.
616
+
617
+
Por supuesto, es posible que ya hayas hecho todo correctamente y el problema no ocurra en tu código. En ese caso, puedes continuar.
616
618
617
619
#### 5.10: Frontend de la Lista de Blogs, paso 10
618
620
@@ -706,12 +708,6 @@ En la parte 3 configuramos la herramienta de estilo de código para el backend [
706
708
707
709
Vite ha instalado ESlint en el proyecto de forma predeterminada, por lo que todo lo que nos queda por hacer es definir nuestra configuración deseada en el archivo <i>.eslintrc.cjs</i>.
708
710
709
-
A continuación, comenzaremos a probar el frontend y, para evitar errores de linter no deseados e irrelevantes instalaremos el paquete [eslint-plugin-jest](https://www.npmjs.com/package/eslint-plugin-jest):
710
-
711
-
```bash
712
-
npm install --save-dev eslint-plugin-jest
713
-
```
714
-
715
711
Creemos un archivo <i>.eslintrc.js</i> con el siguiente contenido:
0 commit comments