Skip to content

Commit

Permalink
test: send error if answer is not 200
Browse files Browse the repository at this point in the history
Co-authored-by: Gabriel Monteiro <gabrielmonteiro1203@gmail.com>
Co-authored-by: Jessica Luiza Silva de Oliveira <jluiza409@gmail.com>
Co-authored-by: Marcella Sanderle <marcellasanderle@gmail.com>
  • Loading branch information
4 people committed Sep 21, 2024
1 parent 994b9f4 commit 73d5f00
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/app/__tests__/idoso.service.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down

0 comments on commit 73d5f00

Please sign in to comment.