mirror of
https://github.com/Horizontal42/summarum.git
synced 2026-11-10 21:31:59 +03:00
fix flaky debounce test: poll with real timers instead of guessing tick count
This commit is contained in:
parent
59df3a7264
commit
d08d807961
1 changed files with 7 additions and 5 deletions
|
|
@ -191,12 +191,14 @@ describe('storage', () => {
|
||||||
// Fast forward past debounce time
|
// Fast forward past debounce time
|
||||||
vi.runAllTimers();
|
vi.runAllTimers();
|
||||||
|
|
||||||
// Allow dynamic import and promise resolution by temporarily using real timers
|
// storage.ts's invoke wrapper does a dynamic import() before calling
|
||||||
|
// invoke(), which resolves over real event-loop ticks (module
|
||||||
|
// transform/IO) even with fake timers active — poll with real timers
|
||||||
|
// until it settles instead of guessing a fixed number of ticks.
|
||||||
vi.useRealTimers();
|
vi.useRealTimers();
|
||||||
await new Promise(resolve => setTimeout(resolve, 0));
|
await vi.waitFor(() => {
|
||||||
vi.useFakeTimers();
|
expect(invoke).toHaveBeenCalledWith('save_documents', { dir: 'custom_dir', contents: JSON.stringify(mockAppData) });
|
||||||
|
});
|
||||||
expect(invoke).toHaveBeenCalledWith('save_documents', { dir: 'custom_dir', contents: JSON.stringify(mockAppData) });
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('flushAppData clears timer and saves immediately', async () => {
|
it('flushAppData clears timer and saves immediately', async () => {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue