From 95490bc2583c0b3e6fe7ec34a7ed800932929f73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nat=C3=A1lia=20Rodrigues?= Date: Fri, 20 Sep 2024 21:19:20 -0300 Subject: [PATCH] test: return error when API reports it Co-authored-by: Gabriel Monteiro Co-authored-by: Jessica Luiza Silva de Oliveira Co-authored-by: Marcella Sanderle --- src/app/__tests__/rotina.service.spec.tsx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/app/__tests__/rotina.service.spec.tsx b/src/app/__tests__/rotina.service.spec.tsx index 57e30978..55a81c16 100644 --- a/src/app/__tests__/rotina.service.spec.tsx +++ b/src/app/__tests__/rotina.service.spec.tsx @@ -183,6 +183,22 @@ describe("getAllRotina", () => { } } }); + + it("deve lançar um erro quando a API retorna um erro", async () => { + // Mock para simular uma resposta de erro + global.fetch = jest.fn().mockResolvedValue({ + json: async () => ({ + message: "Mensagem de erro", + status: 400, + }), + status: 400, + }); + + const filter = {}; + const order = {}; + + await expect(getAllRotina(filter, order)).rejects.toThrow("Mensagem de erro"); + }); }); describe("deleteRotina", () => {