diff --git a/plugins/search-backend-node/src/runPeriodically.test.ts b/plugins/search-backend-node/src/runPeriodically.test.ts index 4d8e991b9e..0f2ee44b8d 100644 --- a/plugins/search-backend-node/src/runPeriodically.test.ts +++ b/plugins/search-backend-node/src/runPeriodically.test.ts @@ -18,7 +18,11 @@ import { runPeriodically } from './runPeriodically'; jest.useFakeTimers(); describe('runPeriodically', () => { - const flushPromises = () => new Promise(setImmediate); + const flushPromises = async () => { + const promise = new Promise(resolve => process.nextTick(resolve)); + jest.runAllTicks(); + await promise; + }; const advanceTimersByTime = async (time: number) => { jest.advanceTimersByTime(time); // Advancing the time with jest doesn't run all promises, but only sync code