runner icon indicating copy to clipboard operation
runner copied to clipboard

Question - How can I test the call of a method with toHaveBeenCalled()?

Open diegormb06 opened this issue 5 months ago • 2 comments

When I tried to run the test with toHaveBeenCalled, I got an error saying that the argument must be a mock or a spy. How can I create a spy to test a method call?

the test function is:

  test('updates a product', async ({ expect }) => {
    const updateData = { title: 'Updated Product' }
    mockProductRepository.update = async () => true

    const result = await productService.updateProduct(1, updateData)

    expect(result).toEqual(true)
    expect(mockProductRepository.update).toHaveBeenCalledWith(1, updateData)
  })

te error is: image

diegormb06 avatar Sep 29 '24 15:09 diegormb06