Question - How can I test the call of a method with toHaveBeenCalled()?
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:
Not sure if this is directory related to Japa, since the mocking capabilities are part of the expect library. However, how do you create the mockProductRepository object?
I just create a object with the methods, like I use to do with jest.
const mockProductRepository = {
getAll: async () => ({}) as Paginated<Product>,
update: async () => true,
delete: async () => true,
}
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.