-1
What should I put on expect
to check if the product has been deleted once it returns nothing?
it('should be able to delete a product.', async () => {
const product = await createProductService.execute({
name: 'Bola',
category: 'Esportes',
price: 13.3,
value: 8,
});
await fakeProducRepositories.delete(product.id);
expect(product);
});
Depends. The normal would return nothing, ie,
undefined
, then aawait expect(fakeProducRepositories.delete(product.id)).resolves.toBe(undefined)
would not solve?– Cmte Cardeal
it worked obg, but with when I put await in front of the fakeProducRepositories it rejects knows why of that?
– mumu
'Cause that’s how the Jest works. Obviously it doesn’t have to be like this. I did it to make the code shorter, but it can be done:
const response = await fakeProducRepositories.delete(product.id);
and thenexpect(response).toBe(undefined)
. The way I wrote is mostly aimed at verifying whether a Exception during the execution of an asynchronous function, i.e., whether that function was Rejected.– Cmte Cardeal
our trip and put the await in the wrong place went super right vlw bro
– mumu
.delete
returns something in failure? If not, the only way to test is by searching for the product, and if not, then "success" in the test.– Rafael Tavares
you would have an example to try to find but ta hard. kkkk
– mumu