diff --git a/packages/utils/tests/resolveAfter.test.ts b/packages/utils/tests/resolveAfter.test.ts new file mode 100644 index 00000000000..e4d9bc53545 --- /dev/null +++ b/packages/utils/tests/resolveAfter.test.ts @@ -0,0 +1,24 @@ +import { resolveAfter } from '../src/resolveAfter'; + +describe('resolveAfter', () => { + jest.useFakeTimers(); + + it('resolves after specified time', async () => { + const { promise } = resolveAfter(200, 'foo'); + + jest.advanceTimersByTime(200); + + await expect(promise).resolves.toBe('foo'); + }); + + it('rejects if the promise is rejected', async () => { + const { promise, reject } = resolveAfter(200); + + // Reject the promise after 100ms + setTimeout(() => reject(new Error('bar')), 100); + + jest.advanceTimersByTime(100); + + await expect(promise).rejects.toThrow('bar'); + }); +});