Me sale el error <code>Error: expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 ...

Pregunta de la clase:
Implementar provider mock
María Paz Muñoz Parra

María Paz Muñoz Parra

Pregunta
studenthace 4 años

Me sale el error

Error: expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0

¿Qué debería revisar?

4 respuestas
para escribir tu comentario
    Jair Israel Avilés Eusebio

    Jair Israel Avilés Eusebio

    studenthace 4 años

    Al parecer no estas simulando el click en el boton. Supongo te falta la instruccion siguiente.

    ... wrapper.find('button').simulate('click') ...
    Luis Gerardo López Hernández

    Luis Gerardo López Hernández

    studenthace 4 años

    intenta con el mismo codigo de la clase a ver si funciona, si si pues nada mas comparalo con tu codigo

    María Paz Muñoz Parra

    María Paz Muñoz Parra

    studenthace 4 años

    Hola Luis, me sale el mismo error con toHaveBeenCalledTimes(1), por eso lo intentaba con otro método :/

    Pareciera que no se estuviera ejecutando el click con el .simulate('click').

    Luis Gerardo López Hernández

    Luis Gerardo López Hernández

    studenthace 4 años

    es .toHaveBennCalledTimes(1)

    test('Comprobar el boton de comprar', () => { const handleAddToCart = jest.fn() const wrapper = mount( <ProviderMock> <Product product={ProductMock} handleAddToCart={handleAddToCart} /> </ProviderMock> ) wrapper.find('button').simulate('click') expect(handleAddToCart).toHaveBeenCalledTimes(1) })
Curso de Unit Testing con Jest en React

Curso de Unit Testing con Jest en React

Genera tests unitarios de forma sencilla y comprensible en JavaScript con Jest, un framework de testing intuitivo y flexible que te permite crear mocks o personalizar matchers con una interfaz accesible. Domina sus funcionalidades innovadoras y conviértete en un experto en testing de JS con Jest

Curso de Unit Testing con Jest en React
Curso de Unit Testing con Jest en React

Curso de Unit Testing con Jest en React

Genera tests unitarios de forma sencilla y comprensible en JavaScript con Jest, un framework de testing intuitivo y flexible que te permite crear mocks o personalizar matchers con una interfaz accesible. Domina sus funcionalidades innovadoras y conviértete en un experto en testing de JS con Jest