mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-16 19:00:38 +09:00
test(ui): wait for async issue search results
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
parent
622a8e44bf
commit
a3ecc086d9
1 changed files with 21 additions and 6 deletions
|
|
@ -101,6 +101,22 @@ async function flush() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function waitForAssertion(assertion: () => void, attempts = 20) {
|
||||||
|
let lastError: unknown;
|
||||||
|
|
||||||
|
for (let attempt = 0; attempt < attempts; attempt += 1) {
|
||||||
|
try {
|
||||||
|
assertion();
|
||||||
|
return;
|
||||||
|
} catch (error) {
|
||||||
|
lastError = error;
|
||||||
|
await flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw lastError;
|
||||||
|
}
|
||||||
|
|
||||||
function renderWithQueryClient(node: ReactNode, container: HTMLDivElement) {
|
function renderWithQueryClient(node: ReactNode, container: HTMLDivElement) {
|
||||||
const root = createRoot(container);
|
const root = createRoot(container);
|
||||||
const queryClient = new QueryClient({
|
const queryClient = new QueryClient({
|
||||||
|
|
@ -158,12 +174,11 @@ describe("IssuesList", () => {
|
||||||
container,
|
container,
|
||||||
);
|
);
|
||||||
|
|
||||||
await flush();
|
await waitForAssertion(() => {
|
||||||
await flush();
|
expect(mockIssuesApi.list).toHaveBeenCalledWith("company-1", { q: "server", projectId: undefined });
|
||||||
|
expect(container.textContent).toContain("Server result");
|
||||||
expect(mockIssuesApi.list).toHaveBeenCalledWith("company-1", { q: "server", projectId: undefined });
|
expect(container.textContent).not.toContain("Local issue");
|
||||||
expect(container.textContent).toContain("Server result");
|
});
|
||||||
expect(container.textContent).not.toContain("Local issue");
|
|
||||||
|
|
||||||
act(() => {
|
act(() => {
|
||||||
root.unmount();
|
root.unmount();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue