fix some test style and SWRConfig type compilation
This commit is contained in:
parent
a69e559890
commit
9a9629249e
@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { renderHook } from "@testing-library/preact-hooks"
|
import { renderHook } from "@testing-library/preact-hooks"
|
||||||
import { useAsync } from "../../src/hooks/async"
|
import { useAsync } from "../../src/hooks/async.js"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -37,8 +37,8 @@ test('listener', async () => {
|
|||||||
|
|
||||||
const { result } = renderHook(() => useListener(addWorldToTheEnd))
|
const { result } = renderHook(() => useListener(addWorldToTheEnd))
|
||||||
|
|
||||||
if (!result.current) {
|
|
||||||
expect(result.current).toBeDefined()
|
expect(result.current).toBeDefined()
|
||||||
|
if (!result.current) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ interface TestingContextProps {
|
|||||||
children?: ComponentChildren;
|
children?: ComponentChildren;
|
||||||
}
|
}
|
||||||
export function TestingContext({ children }: TestingContextProps): VNode {
|
export function TestingContext({ children }: TestingContextProps): VNode {
|
||||||
|
const SC: any = SWRConfig
|
||||||
return (
|
return (
|
||||||
<BackendContextProvider defaultUrl="http://backend" initialToken="token">
|
<BackendContextProvider defaultUrl="http://backend" initialToken="token">
|
||||||
<InstanceContextProvider
|
<InstanceContextProvider
|
||||||
@ -38,7 +39,7 @@ export function TestingContext({ children }: TestingContextProps): VNode {
|
|||||||
changeToken: () => null,
|
changeToken: () => null,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<SWRConfig value={{ provider: () => new Map() }}>{children}</SWRConfig>
|
<SC value={{ provider: () => new Map() }}>{children}</SC>
|
||||||
</InstanceContextProvider>
|
</InstanceContextProvider>
|
||||||
</BackendContextProvider>
|
</BackendContextProvider>
|
||||||
);
|
);
|
||||||
|
@ -37,7 +37,7 @@ import {
|
|||||||
} from "../../axiosMock.js";
|
} from "../../axiosMock.js";
|
||||||
import { TestingContext } from "./index.js";
|
import { TestingContext } from "./index.js";
|
||||||
|
|
||||||
describe("instance api interaction with details ", () => {
|
describe("instance api interaction with details", () => {
|
||||||
|
|
||||||
it("should evict cache when updating an instance", async () => {
|
it("should evict cache when updating an instance", async () => {
|
||||||
|
|
||||||
@ -59,8 +59,8 @@ describe("instance api interaction with details ", () => {
|
|||||||
{ wrapper: TestingContext }
|
{ wrapper: TestingContext }
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!result.current) {
|
|
||||||
expect(result.current).toBeDefined();
|
expect(result.current).toBeDefined();
|
||||||
|
if (!result.current) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
expect(result.current.query.loading).toBeTruthy();
|
expect(result.current.query.loading).toBeTruthy();
|
||||||
@ -135,8 +135,8 @@ describe("instance api interaction with details ", () => {
|
|||||||
{ wrapper: TestingContext }
|
{ wrapper: TestingContext }
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!result.current) {
|
|
||||||
expect(result.current).toBeDefined();
|
expect(result.current).toBeDefined();
|
||||||
|
if (!result.current) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
expect(result.current.query.loading).toBeTruthy();
|
expect(result.current.query.loading).toBeTruthy();
|
||||||
@ -222,8 +222,8 @@ describe("instance api interaction with details ", () => {
|
|||||||
{ wrapper: TestingContext }
|
{ wrapper: TestingContext }
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!result.current) {
|
|
||||||
expect(result.current).toBeDefined();
|
expect(result.current).toBeDefined();
|
||||||
|
if (!result.current) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
expect(result.current.query.loading).toBeTruthy();
|
expect(result.current.query.loading).toBeTruthy();
|
||||||
@ -284,7 +284,7 @@ describe("instance api interaction with details ", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("instance admin api interaction with listing ", () => {
|
describe("instance admin api interaction with listing", () => {
|
||||||
|
|
||||||
it("should evict cache when creating a new instance", async () => {
|
it("should evict cache when creating a new instance", async () => {
|
||||||
const env = new AxiosMockEnvironment();
|
const env = new AxiosMockEnvironment();
|
||||||
@ -307,8 +307,8 @@ describe("instance admin api interaction with listing ", () => {
|
|||||||
{ wrapper: TestingContext }
|
{ wrapper: TestingContext }
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!result.current) {
|
|
||||||
expect(result.current).toBeDefined();
|
expect(result.current).toBeDefined();
|
||||||
|
if (!result.current) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
expect(result.current.query.loading).toBeTruthy();
|
expect(result.current.query.loading).toBeTruthy();
|
||||||
@ -397,8 +397,8 @@ describe("instance admin api interaction with listing ", () => {
|
|||||||
{ wrapper: TestingContext }
|
{ wrapper: TestingContext }
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!result.current) {
|
|
||||||
expect(result.current).toBeDefined();
|
expect(result.current).toBeDefined();
|
||||||
|
if (!result.current) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
expect(result.current.query.loading).toBeTruthy();
|
expect(result.current.query.loading).toBeTruthy();
|
||||||
@ -481,8 +481,8 @@ describe("instance admin api interaction with listing ", () => {
|
|||||||
{ wrapper: TestingContext }
|
{ wrapper: TestingContext }
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!result.current) {
|
|
||||||
expect(result.current).toBeDefined();
|
expect(result.current).toBeDefined();
|
||||||
|
if (!result.current) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
expect(result.current.query.loading).toBeTruthy();
|
expect(result.current.query.loading).toBeTruthy();
|
||||||
@ -545,7 +545,7 @@ describe("instance admin api interaction with listing ", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("instance management api interaction with listing ", () => {
|
describe("instance management api interaction with listing", () => {
|
||||||
|
|
||||||
it("should evict cache when updating an instance", async () => {
|
it("should evict cache when updating an instance", async () => {
|
||||||
const env = new AxiosMockEnvironment();
|
const env = new AxiosMockEnvironment();
|
||||||
@ -569,8 +569,8 @@ describe("instance management api interaction with listing ", () => {
|
|||||||
{ wrapper: TestingContext }
|
{ wrapper: TestingContext }
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!result.current) {
|
|
||||||
expect(result.current).toBeDefined();
|
expect(result.current).toBeDefined();
|
||||||
|
if (!result.current) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
expect(result.current.query.loading).toBeTruthy();
|
expect(result.current.query.loading).toBeTruthy();
|
||||||
|
@ -62,8 +62,8 @@ describe("order api interaction with listing", () => {
|
|||||||
return { query, api };
|
return { query, api };
|
||||||
}, { wrapper: TestingContext });
|
}, { wrapper: TestingContext });
|
||||||
|
|
||||||
if (!result.current) {
|
|
||||||
expect(result.current).toBeDefined();
|
expect(result.current).toBeDefined();
|
||||||
|
if (!result.current) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,8 +143,8 @@ describe("order api interaction with listing", () => {
|
|||||||
return { query, api };
|
return { query, api };
|
||||||
}, { wrapper: TestingContext });
|
}, { wrapper: TestingContext });
|
||||||
|
|
||||||
if (!result.current) {
|
|
||||||
expect(result.current).toBeDefined();
|
expect(result.current).toBeDefined();
|
||||||
|
if (!result.current) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,8 +234,8 @@ describe("order api interaction with listing", () => {
|
|||||||
return { query, api };
|
return { query, api };
|
||||||
}, { wrapper: TestingContext });
|
}, { wrapper: TestingContext });
|
||||||
|
|
||||||
if (!result.current) {
|
|
||||||
expect(result.current).toBeDefined();
|
expect(result.current).toBeDefined();
|
||||||
|
if (!result.current) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -305,8 +305,8 @@ describe("order api interaction with details", () => {
|
|||||||
return { query, api };
|
return { query, api };
|
||||||
}, { wrapper: TestingContext });
|
}, { wrapper: TestingContext });
|
||||||
|
|
||||||
if (!result.current) {
|
|
||||||
expect(result.current).toBeDefined();
|
expect(result.current).toBeDefined();
|
||||||
|
if (!result.current) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -374,8 +374,8 @@ describe("order api interaction with details", () => {
|
|||||||
return { query, api };
|
return { query, api };
|
||||||
}, { wrapper: TestingContext });
|
}, { wrapper: TestingContext });
|
||||||
|
|
||||||
if (!result.current) {
|
|
||||||
expect(result.current).toBeDefined();
|
expect(result.current).toBeDefined();
|
||||||
|
if (!result.current) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ import {
|
|||||||
AxiosMockEnvironment
|
AxiosMockEnvironment
|
||||||
} from "../../axiosMock.js";
|
} from "../../axiosMock.js";
|
||||||
|
|
||||||
describe("product api interaction with listing ", () => {
|
describe("product api interaction with listing", () => {
|
||||||
it("should evict cache when creating a product", async () => {
|
it("should evict cache when creating a product", async () => {
|
||||||
const env = new AxiosMockEnvironment();
|
const env = new AxiosMockEnvironment();
|
||||||
|
|
||||||
@ -56,8 +56,8 @@ describe("product api interaction with listing ", () => {
|
|||||||
{ wrapper: TestingContext }
|
{ wrapper: TestingContext }
|
||||||
); // get products -> loading
|
); // get products -> loading
|
||||||
|
|
||||||
if (!result.current) {
|
|
||||||
expect(result.current).toBeDefined();
|
expect(result.current).toBeDefined();
|
||||||
|
if (!result.current) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
expect(result.current.query.loading).toBeTruthy();
|
expect(result.current.query.loading).toBeTruthy();
|
||||||
@ -141,8 +141,8 @@ describe("product api interaction with listing ", () => {
|
|||||||
{ wrapper: TestingContext }
|
{ wrapper: TestingContext }
|
||||||
); // get products -> loading
|
); // get products -> loading
|
||||||
|
|
||||||
if (!result.current) {
|
|
||||||
expect(result.current).toBeDefined();
|
expect(result.current).toBeDefined();
|
||||||
|
if (!result.current) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
expect(result.current.query.loading).toBeTruthy();
|
expect(result.current.query.loading).toBeTruthy();
|
||||||
@ -218,8 +218,8 @@ describe("product api interaction with listing ", () => {
|
|||||||
{ wrapper: TestingContext }
|
{ wrapper: TestingContext }
|
||||||
); // get products -> loading
|
); // get products -> loading
|
||||||
|
|
||||||
if (!result.current) {
|
|
||||||
expect(result.current).toBeDefined();
|
expect(result.current).toBeDefined();
|
||||||
|
if (!result.current) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
expect(result.current.query.loading).toBeTruthy();
|
expect(result.current.query.loading).toBeTruthy();
|
||||||
@ -289,8 +289,8 @@ describe("product api interaction with details", () => {
|
|||||||
return { query, api };
|
return { query, api };
|
||||||
}, { wrapper: TestingContext });
|
}, { wrapper: TestingContext });
|
||||||
|
|
||||||
if (!result.current) {
|
|
||||||
expect(result.current).toBeDefined();
|
expect(result.current).toBeDefined();
|
||||||
|
if (!result.current) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
expect(result.current.query.loading).toBeTruthy();
|
expect(result.current.query.loading).toBeTruthy();
|
||||||
|
@ -41,7 +41,7 @@ import {
|
|||||||
} from "../../axiosMock.js";
|
} from "../../axiosMock.js";
|
||||||
import { TestingContext } from "./index.js";
|
import { TestingContext } from "./index.js";
|
||||||
|
|
||||||
describe("reserve api interaction with listing ", () => {
|
describe("reserve api interaction with listing", () => {
|
||||||
it("should evict cache when creating a reserve", async () => {
|
it("should evict cache when creating a reserve", async () => {
|
||||||
const env = new AxiosMockEnvironment();
|
const env = new AxiosMockEnvironment();
|
||||||
|
|
||||||
@ -65,8 +65,8 @@ describe("reserve api interaction with listing ", () => {
|
|||||||
{ wrapper: TestingContext }
|
{ wrapper: TestingContext }
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!result.current) {
|
|
||||||
expect(result.current).toBeDefined();
|
expect(result.current).toBeDefined();
|
||||||
|
if (!result.current) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
expect(result.current.query.loading).toBeTruthy();
|
expect(result.current.query.loading).toBeTruthy();
|
||||||
@ -171,8 +171,8 @@ describe("reserve api interaction with listing ", () => {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!result.current) {
|
|
||||||
expect(result.current).toBeDefined();
|
expect(result.current).toBeDefined();
|
||||||
|
if (!result.current) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
expect(result.current.query.loading).toBeTruthy();
|
expect(result.current.query.loading).toBeTruthy();
|
||||||
@ -260,8 +260,8 @@ describe("reserve api interaction with details", () => {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!result.current) {
|
|
||||||
expect(result.current).toBeDefined();
|
expect(result.current).toBeDefined();
|
||||||
|
if (!result.current) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
expect(result.current.query.loading).toBeTruthy();
|
expect(result.current.query.loading).toBeTruthy();
|
||||||
@ -353,8 +353,8 @@ describe("reserve api interaction with details", () => {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!result.current) {
|
|
||||||
expect(result.current).toBeDefined();
|
expect(result.current).toBeDefined();
|
||||||
|
if (!result.current) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
expect(result.current.query.loading).toBeTruthy();
|
expect(result.current.query.loading).toBeTruthy();
|
||||||
@ -448,8 +448,8 @@ describe("reserve api interaction with tip details", () => {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!result.current) {
|
|
||||||
expect(result.current).toBeDefined();
|
expect(result.current).toBeDefined();
|
||||||
|
if (!result.current) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
expect(result.current.query.loading).toBeTruthy();
|
expect(result.current.query.loading).toBeTruthy();
|
||||||
|
@ -62,8 +62,8 @@ describe("transfer api interaction with listing", () => {
|
|||||||
return { query, api };
|
return { query, api };
|
||||||
}, { wrapper: TestingContext });
|
}, { wrapper: TestingContext });
|
||||||
|
|
||||||
if (!result.current) {
|
|
||||||
expect(result.current).toBeDefined();
|
expect(result.current).toBeDefined();
|
||||||
|
if (!result.current) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,14 +42,11 @@ function getFiles(dir: string, files_: string[] = []) {
|
|||||||
const STORIES_NAME_REGEX = RegExp(".*.stories.tsx");
|
const STORIES_NAME_REGEX = RegExp(".*.stories.tsx");
|
||||||
|
|
||||||
function render(vnode: VNode) {
|
function render(vnode: VNode) {
|
||||||
|
const SC: any = SWRConfig
|
||||||
return originalRender(
|
return originalRender(
|
||||||
<SWRConfig
|
<SC value={{ provider: () => new Map() }}>
|
||||||
value={{
|
|
||||||
provider: () => new Map(),
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{vnode}
|
{vnode}
|
||||||
</SWRConfig>,
|
</SC>,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user