# Testing Unitario y de integración

### Jest

{% tabs %}
{% tab title="Sintaxis BDD" %}

```javascript
  describe('module', () => {
    it('test case', () => {
      /* ... */`
      
    })
  })
```

{% endtab %}

{% tab title="Métodos 'ciclo de vida'" %}

```javascript
  beforeEach()
  afterEach()

  beforeAll()
  afterAll()
```

{% endtab %}

{% tab title="Aserciones básica" %}

```javascript
  expect(value)

    .not
    .toBe(value)
    .toBeInstanceOf(Class)
    .toBeTruthy()
    .toEqual(value)
    .toHaveProperty(keyPath, value)
    .toMatch(regexOrString)
    .toMatchObject(object)
    .toThrow(error)
    .toThrowErrorMatchingSnapshot()
```

{% endtab %}

{% tab title="Mocks" %}

```javascript
  const fn = jest.fn()
  const fn = jest.fn(() => 'hello')

  expect(fn)
    .toHaveBeenCalled()
    .toHaveBeenCalledTimes(number)
    .toHaveBeenCalledWith(arg1, arg2, ...)
```

{% endtab %}
{% endtabs %}

{% embed url="<https://devhints.io/jest>" %}

### @testing-library/react

{% tabs %}
{% tab title="Métodos de renderizado" %}

```javascript
  render()
  renderHook()
  act()
```

{% embed url="<https://testing-library.com/docs/react-testing-library/api#render>" %}
{% endtab %}
{% endtabs %}

### @testing-library/jest-dom

{% tabs %}
{% tab title="métodos de búsqueda" %}

```javascript
getBy()
findBy()
queryBy()
getAllBy()
findAllBy()
queryAllBy()
```

{% embed url="<https://testing-library.com/docs/react-testing-library/cheatsheet/#queries>" %}
{% endtab %}
{% endtabs %}


---

# 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/testing-unitario-y-de-integracion.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.
