Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
thetarnav authored and github-actions[bot] committed Aug 26, 2022
1 parent 02eac57 commit b497db1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
14 changes: 9 additions & 5 deletions packages/fetch/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const fetchMock: typeof fetch = (input: RequestInfo | URL, init?: RequestInit):
}
});

describe('fetch primitive', () => {
describe("fetch primitive", () => {
test("will fetch json data", () =>
new Promise<void>(resolve => {
createRoot(dispose => {
Expand Down Expand Up @@ -81,9 +81,11 @@ describe('fetch primitive', () => {

test("will abort a request without an error", () =>
createRoot(dispose => {
const [ready, { abort }] = createFetch<typeof mockResponseBody>(mockUrl, { fetch: fetchMock }, [
withAbort()
]);
const [ready, { abort }] = createFetch<typeof mockResponseBody>(
mockUrl,
{ fetch: fetchMock },
[withAbort()]
);
abort!();
expect(ready.aborted).toBe(true);
createEffect(() => {
Expand Down Expand Up @@ -193,7 +195,9 @@ describe('fetch primitive', () => {
calls++;
return Promise.resolve(mockResponse);
};
const [ready] = createFetch<typeof mockResponseBody>(url, { fetch }, [withRefetchEvent({ on: ['refetch'] })]);
const [ready] = createFetch<typeof mockResponseBody>(url, { fetch }, [
withRefetchEvent({ on: ["refetch"] })
]);
createEffect(() => {
const data = ready.error ? undefined : ready();
if (!data) {
Expand Down
14 changes: 9 additions & 5 deletions packages/fetch/test/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ if (!globalThis.Response) {
return () => Promise.resolve(JSON.parse((this.body ?? "").toString()));
}
}
(globalThis.window as any || {}).Response = ResponseMock;
((globalThis.window as any) || {}).Response = ResponseMock;
(globalThis as any).Response = ResponseMock;
}

if (!globalThis.Headers) {
class HeadersMock {
private headers: Record<string, string> = {};
append(key: string, value: string) {
this.headers[key] = `${this.headers[key]}${this.headers.key ? ' ' : ''}${value}`;
return this.headers[key]
this.headers[key] = `${this.headers[key]}${this.headers.key ? " " : ""}${value}`;
return this.headers[key];
}
delete(key: string) {
delete this.headers[key];
Expand Down Expand Up @@ -98,9 +98,13 @@ if (!globalThis.Headers) {
return Object.values(this.headers);
}
}
(globalThis.window as any || {}).Headers = HeadersMock;
((globalThis.window as any) || {}).Headers = HeadersMock;
(globalThis as any).Headers = HeadersMock;
}

// we need to remove this in order to test the server mock
Object.defineProperty(globalThis, 'fetch', { configurable: true, enumerable: true, value: undefined });
Object.defineProperty(globalThis, "fetch", {
configurable: true,
enumerable: true,
value: undefined
});

0 comments on commit b497db1

Please sign in to comment.