mirror of
https://github.com/vector-im/element-call.git
synced 2026-02-02 04:05:56 +00:00
fetch returns a response code of 0 when it successfully loads a `file://` resource. This means we can't just rely on `response.ok`. Required for https://github.com/element-hq/element-call/issues/2994
31 lines
781 B
TypeScript
31 lines
781 B
TypeScript
/*
|
|
Copyright 2025 New Vector Ltd.
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
|
Please see LICENSE in the repository root for full details.
|
|
*/
|
|
|
|
import { expect, describe, it } from "vitest";
|
|
|
|
import { isFailure } from "./fetch";
|
|
|
|
describe("isFailure", () => {
|
|
it("returns false for a successful response", () => {
|
|
expect(isFailure({ ok: true, url: "https://foo.com" } as Response)).toBe(
|
|
false,
|
|
);
|
|
});
|
|
|
|
it("returns true for a failed response", () => {
|
|
expect(isFailure({ ok: false, url: "https://foo.com" } as Response)).toBe(
|
|
true,
|
|
);
|
|
});
|
|
|
|
it("returns false for a file:// URL with status 0", () => {
|
|
expect(
|
|
isFailure({ ok: false, url: "file://foo", status: 0 } as Response),
|
|
).toBe(false);
|
|
});
|
|
});
|