From 73d5f0038c5c4dfd32b389a61dc908497ff2bb81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nat=C3=A1lia=20Rodrigues?= Date: Fri, 20 Sep 2024 21:41:39 -0300 Subject: [PATCH] test: send error if answer is not 200 Co-authored-by: Gabriel Monteiro Co-authored-by: Jessica Luiza Silva de Oliveira Co-authored-by: Marcella Sanderle --- src/app/__tests__/idoso.service.spec.tsx | 26 ++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/app/__tests__/idoso.service.spec.tsx b/src/app/__tests__/idoso.service.spec.tsx index 49b140fa..5ed7dade 100644 --- a/src/app/__tests__/idoso.service.spec.tsx +++ b/src/app/__tests__/idoso.service.spec.tsx @@ -195,6 +195,32 @@ describe("getAllIdoso", () => { } } }); + + it("deve lançar um erro se o status da resposta não for 200", async () => { + const order: IOrder = { + column: "descricao", + dir: "DESC", + }; + const idUsuario = 1; + + // Mock para simular uma resposta de erro + global.fetch = jest.fn().mockResolvedValue({ + json: async () => ({ + data: null, + message: "Mensagem de erro", + status: 400, + }), + status: 400, + }); + + try { + await getAllIdoso(idUsuario, order); + } catch (error) { + if (error instanceof Error) { + expect(error.message).toBe("Mensagem de erro"); + } + } + }); }); describe("deleteIdoso", () => {