# Ejercicio sesión 2

En el Ejemplo 4 (Hook) hemos visto como podemos hacer un test unitario de un Hook creando un componente `TestingComponent()` que llame al hook que queremos testear (`useCart()`)

Otra forma para testear hooks en react es usar la función [`renderHook()`](https://testing-library.com/docs/react-testing-library/api/#renderhook)

¿Cómo quedaría el test del ejemplo 4 usando la función `renderHook()` en lugar de creando un componente `TestingComponent()` al vuelo ?

{% content-ref url="/pages/DbTt4D29CaxN4VBywZiV" %}
[Ejemplo 4 - hook](/buenas-practicas-con-react/sesion-2/5.-testing/proyecto-de-ejemplo/ejemplo-4-hook.md)
{% endcontent-ref %}

```jsx
import { useCart } from "./octo-marketplace/src/hooks/use-cart";
import {renderHook} from '@testing-library/react'

test('render happy case', () => {
  // given
  
  // when
  renderHook(...)
  
  // then
})
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://manu-artero-anguita.gitbook.io/buenas-practicas-con-react/sesion-2/5.-testing/ejercicio-sesion-2.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
