fetch plugin test: testing what happens on 400+ status codes (and rising coverage to 100%; ref. #8)

merge-requests/1/head
Michał 'rysiek' Woźniak 2021-08-29 14:19:28 +00:00
rodzic 9e13d8980a
commit da86c0eba1
1 zmienionych plików z 22 dodań i 0 usunięć

Wyświetl plik

@ -62,4 +62,26 @@ describe("plugin: fetch", () => {
expect(response.headers.has('X-LibResilient-Etag')).toEqual(true)
expect(response.headers.get('X-LibResilient-ETag')).toEqual('TestingETagHeader')
});
test("it should throw an error when HTTP status is >= 400", async () => {
global.fetch.mockImplementation((url, init) => {
const response = new Response(
new Blob(
["Not Found"],
{type: "text/plain"}
),
{
status: 404,
statusText: "Not Found",
url: url
});
return Promise.resolve(response);
});
require("../../plugins/fetch.js");
expect.assertions(1)
expect(self.LibResilientPlugins[0].fetch('https://resilient.is/test.json')).rejects.toThrow(Error)
});
});