Skip to content

Commit

Permalink
test: use async imports directly in variable declarations (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterckx committed Oct 17, 2024
1 parent 9d3ea62 commit 7d373e3
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 22 deletions.
6 changes: 1 addition & 5 deletions tests/authentication.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ jest.unstable_mockModule("react-idle-timer", () => ({
useIdleTimer: jest.fn(),
}));

let shouldReleaseToken: typeof import("../src/providers/authentication").shouldReleaseToken;

beforeAll(async () => {
({ shouldReleaseToken } = await import("../src/providers/authentication"));
});
const { shouldReleaseToken } = await import("../src/providers/authentication");

describe("authentication", () => {
// Boolean constants.
Expand Down
13 changes: 4 additions & 9 deletions tests/azulFileDownload.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,10 @@ jest.unstable_mockModule("../src/hooks/useFileLocation", () => ({
useFileLocation: jest.fn(),
}));

let AzulFileDownload: typeof import("../src/components/Index/components/AzulFileDownload/azulFileDownload").AzulFileDownload;
let useFileLocation: typeof import("../src/hooks/useFileLocation").useFileLocation;

beforeAll(async () => {
({ AzulFileDownload } = await import(
"../src/components/Index/components/AzulFileDownload/azulFileDownload"
));
({ useFileLocation } = await import("../src/hooks/useFileLocation"));
});
const { AzulFileDownload } = await import(
"../src/components/Index/components/AzulFileDownload/azulFileDownload"
);
const { useFileLocation } = await import("../src/hooks/useFileLocation");

describe("AzulFileDownload", () => {
const FILE_URL = "https://example.com/storage/file";
Expand Down
5 changes: 2 additions & 3 deletions tests/fetchApi.ts → tests/fetchApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ jest.unstable_mockModule("../src/shared/utils", () => ({
getURL: (): string => "http://example.com",
}));

const { fetchApi } = await import("../src/entity/common/client");

const actualSetTimeout = setTimeout;

const mockSetTimeout = jest
Expand All @@ -14,8 +16,6 @@ const mockSetTimeout = jest
else callback();
}) as typeof setTimeout);

let fetchApi: typeof import("../src/entity/common/client").fetchApi;

beforeAll(async () => {
fetchMock.doMock();
globalThis.fetch = ((...args) => {
Expand All @@ -24,7 +24,6 @@ beforeAll(async () => {
AbortSignal.prototype.throwIfAborted = function (): void {
if (this.aborted) throw this.reason;
};
({ fetchApi } = await import("../src/entity/common/client"));
});

describe("api", () => {
Expand Down
6 changes: 1 addition & 5 deletions tests/useFileLocation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ jest.unstable_mockModule("../src/hooks/useRequestFileLocation", () => ({
useRequestFileLocation: jest.fn(),
}));

let buildFetchFileUrl: typeof import("../src/hooks/useFileLocation").buildFetchFileUrl;

beforeAll(async () => {
({ buildFetchFileUrl } = await import("../src/hooks/useFileLocation"));
});
const { buildFetchFileUrl } = await import("../src/hooks/useFileLocation");

describe("useFileLocation", () => {
describe("build file URL", () => {
Expand Down

0 comments on commit 7d373e3

Please sign in to comment.