mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix tests
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
e2e7bc460b
commit
0432d5040c
@ -14,7 +14,7 @@ export type Fetch = (url: string, init?: RequestInit) => Promise<Response>;
|
|||||||
|
|
||||||
const fetchInjectable = getInjectable({
|
const fetchInjectable = getInjectable({
|
||||||
id: "fetch",
|
id: "fetch",
|
||||||
instantiate: () => fetch,
|
instantiate: (): Fetch => fetch,
|
||||||
causesSideEffects: true,
|
causesSideEffects: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -21,8 +21,7 @@ import { flushPromises } from "../../test-utils/flush-promises";
|
|||||||
import createKubeJsonApiInjectable from "../create-kube-json-api.injectable";
|
import createKubeJsonApiInjectable from "../create-kube-json-api.injectable";
|
||||||
import type { IKubeWatchEvent } from "../kube-watch-event";
|
import type { IKubeWatchEvent } from "../kube-watch-event";
|
||||||
import type { KubeJsonApiDataFor } from "../kube-object";
|
import type { KubeJsonApiDataFor } from "../kube-object";
|
||||||
import { Headers as NodeFetchHeaders } from "node-fetch";
|
import type { Response, Headers as NodeFetchHeaders } from "node-fetch";
|
||||||
import type { Response } from "node-fetch";
|
|
||||||
import AbortController from "abort-controller";
|
import AbortController from "abort-controller";
|
||||||
|
|
||||||
const createMockResponseFromString = (url: string, data: string, statusCode = 200) => {
|
const createMockResponseFromString = (url: string, data: string, statusCode = 200) => {
|
||||||
@ -33,7 +32,7 @@ const createMockResponseFromString = (url: string, data: string, statusCode = 20
|
|||||||
blob: jest.fn(async () => { throw new Error("blob() is not supported"); }),
|
blob: jest.fn(async () => { throw new Error("blob() is not supported"); }),
|
||||||
body: new PassThrough(),
|
body: new PassThrough(),
|
||||||
bodyUsed: false,
|
bodyUsed: false,
|
||||||
headers: new NodeFetchHeaders(),
|
headers: new Headers() as NodeFetchHeaders,
|
||||||
json: jest.fn(async () => JSON.parse(await res.text())),
|
json: jest.fn(async () => JSON.parse(await res.text())),
|
||||||
ok: 200 <= statusCode && statusCode < 300,
|
ok: 200 <= statusCode && statusCode < 300,
|
||||||
redirected: 300 <= statusCode && statusCode < 400,
|
redirected: 300 <= statusCode && statusCode < 400,
|
||||||
@ -43,8 +42,7 @@ const createMockResponseFromString = (url: string, data: string, statusCode = 20
|
|||||||
text: jest.fn(async () => data),
|
text: jest.fn(async () => data),
|
||||||
type: "basic",
|
type: "basic",
|
||||||
url,
|
url,
|
||||||
textConverted: jest.fn(async () => { throw new Error("textConverted() is not supported"); }),
|
formData: jest.fn(async () => { throw new Error("formData() is not supported"); }),
|
||||||
timeout: 0,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
@ -58,7 +56,7 @@ const createMockResponseFromStream = (url: string, stream: NodeJS.ReadableStream
|
|||||||
blob: jest.fn(async () => { throw new Error("blob() is not supported"); }),
|
blob: jest.fn(async () => { throw new Error("blob() is not supported"); }),
|
||||||
body: stream,
|
body: stream,
|
||||||
bodyUsed: false,
|
bodyUsed: false,
|
||||||
headers: new NodeFetchHeaders(),
|
headers: new Headers() as NodeFetchHeaders,
|
||||||
json: jest.fn(async () => JSON.parse(await res.text())),
|
json: jest.fn(async () => JSON.parse(await res.text())),
|
||||||
ok: 200 <= statusCode && statusCode < 300,
|
ok: 200 <= statusCode && statusCode < 300,
|
||||||
redirected: 300 <= statusCode && statusCode < 400,
|
redirected: 300 <= statusCode && statusCode < 400,
|
||||||
@ -76,8 +74,7 @@ const createMockResponseFromStream = (url: string, stream: NodeJS.ReadableStream
|
|||||||
}),
|
}),
|
||||||
type: "basic",
|
type: "basic",
|
||||||
url,
|
url,
|
||||||
textConverted: jest.fn(async () => { throw new Error("textConverted() is not supported"); }),
|
formData: jest.fn(async () => { throw new Error("formData() is not supported"); }),
|
||||||
timeout: 0,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user