Skip to content

Build your personal knowledge base with Trilium Notes

test(client): flush deferred import-error timer before asserting toast

Elian Dorane57c0c9070bc
diff --git a/apps/client/src/services/import.spec.ts b/apps/client/src/services/import.spec.ts
index 6e71592b24..d067c8849c 100644
--- a/apps/client/src/services/import.spec.ts
+++ b/apps/client/src/services/import.spec.ts
@@ -102,18 +102,23 @@ describe("uploadFiles", () => {
// the test env, so t() returns the key and never interpolates). We assert
// the call args/structure rather than a human-readable translated string.
const tSpy = vi.spyOn(i18n, "t");
+ vi.useFakeTimers();
try {
($ as any).ajax = vi.fn(async (opts: any) => {
opts.error({ responseText: "boom" });
return {};
});
await uploadFiles("notes", "p1", ["a"], { shrinkImages: false });
+ // The error toast is deferred (so a WebSocket taskError can claim the taskId first and
+ // win), so the fallback only fires after IMPORT_ERROR_FALLBACK_DELAY — flush it first.
+ vi.runOnlyPendingTimers();
expect(toastService.showError).toHaveBeenCalledTimes(1);
// The xhr.responseText ("boom") must be forwarded into the message
// interpolation, not dropped or replaced with the whole xhr object.
expect(tSpy).toHaveBeenCalledWith("import.failed", { message: "boom" });
} finally {
tSpy.mockRestore();
+ vi.useRealTimers();
}
});