AxiosStrategy-NoProxy.spec.js (hoppscotch-2.0.0) | : | AxiosStrategy-NoProxy.spec.js (hoppscotch-2.1.0) | ||
---|---|---|---|---|
import axios from "axios" | import axios from "axios" | |||
import axiosStrategy from "../AxiosStrategy" | import axiosStrategy from "../AxiosStrategy" | |||
import { JsonFormattedError } from "~/helpers/utils/JsonFormattedError" | ||||
jest.mock("axios") | jest.mock("axios") | |||
jest.mock("~/newstore/settings", () => { | jest.mock("~/newstore/settings", () => { | |||
return { | return { | |||
__esModule: true, | __esModule: true, | |||
settingsStore: { | settingsStore: { | |||
value: { | value: { | |||
PROXY_ENABLED: false, | PROXY_ENABLED: false, | |||
}, | }, | |||
}, | }, | |||
skipping to change at line 45 | skipping to change at line 46 | |||
expect.objectContaining({ | expect.objectContaining({ | |||
responseType: "arraybuffer", | responseType: "arraybuffer", | |||
}) | }) | |||
) | ) | |||
}) | }) | |||
test("resolves successful requests", async () => { | test("resolves successful requests", async () => { | |||
await expect(axiosStrategy({})).resolves.toBeDefined() | await expect(axiosStrategy({})).resolves.toBeDefined() | |||
}) | }) | |||
test("rejects cancel errors with text 'cancellation'", () => { | test("rejects cancel errors with text 'cancellation'", async () => { | |||
axios.isCancel.mockReturnValueOnce(true) | axios.isCancel.mockReturnValueOnce(true) | |||
axios.mockRejectedValue("err") | axios.mockRejectedValue("err") | |||
expect(axiosStrategy({})).rejects.toBe("cancellation") | await expect(axiosStrategy({})).rejects.toBe("cancellation") | |||
}) | }) | |||
test("rejects non-cancellation errors as-is", () => { | test("rejects non-cancellation errors as-is", async () => { | |||
axios.isCancel.mockReturnValueOnce(false) | axios.isCancel.mockReturnValueOnce(false) | |||
axios.mockRejectedValue("err") | axios.mockRejectedValue("err") | |||
expect(axiosStrategy({})).rejects.toBe("err") | await expect(axiosStrategy({})).rejects.toBe("err") | |||
}) | ||||
test("non-cancellation errors that have response data are thrown", async () | ||||
=> { | ||||
const errorResponse = { error: "errr" } | ||||
axios.isCancel.mockReturnValueOnce(false) | ||||
axios.mockRejectedValue({ | ||||
response: { | ||||
data: Buffer.from(JSON.stringify(errorResponse), "utf8").toString( | ||||
"base64" | ||||
), | ||||
}, | ||||
}) | ||||
await expect(axiosStrategy({})).rejects.toMatchObject( | ||||
new JsonFormattedError(errorResponse) | ||||
) | ||||
}) | }) | |||
}) | }) | |||
}) | }) | |||
End of changes. 5 change blocks. | ||||
4 lines changed or deleted | 22 lines changed or added |