single tests on Ode with jest doubt expect

Asked

Viewed 36 times

-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 a await expect(fakeProducRepositories.delete(product.id)).resolves.toBe(undefined) would not solve?

  • it worked obg, but with when I put await in front of the fakeProducRepositories it rejects knows why of that?

  • '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 then expect(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.

  • our trip and put the await in the wrong place went super right vlw bro

  • .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.

  • you would have an example to try to find but ta hard. kkkk

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.