fix flaky debounce test: poll with real timers instead of guessing tick count

This commit is contained in:
Horizontal42 2026-08-09 16:19:45 +03:00
parent 59df3a7264
commit d08d807961

View file

@ -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 () => {