Skip to content

Commit

Permalink
test: throw API error on hydration
Browse files Browse the repository at this point in the history
  • Loading branch information
Natyrodrigues committed Sep 17, 2024
1 parent 08ca444 commit e3f5f40
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/app/__tests__/metrica.service.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,18 @@ describe("getSomaHidratacao", () => {

expect(result).toBe(100);
});

it("deve lançar um erro se a resposta da API não for bem-sucedida", async () => {
const mockId = 1;
const mockToken = "seu-token-de-exemplo";

const mockResponse = {
status: 500,
json: jest.fn().mockResolvedValue({ message: "Erro na API" }),
};

global.fetch.mockResolvedValue(mockResponse);

await expect(getSomaHidratacao(mockId, mockToken)).rejects.toThrow("Erro na API");
});
});

0 comments on commit e3f5f40

Please sign in to comment.