Skip to content

Commit

Permalink
test(utils): test resolveAfter utils
Browse files Browse the repository at this point in the history
  • Loading branch information
karliatto authored and mroz22 committed Dec 17, 2024
1 parent 5913011 commit 89fffd0
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions packages/utils/tests/resolveAfter.test.ts
Original file line number Diff line number Diff line change
@@ -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');
});
});

0 comments on commit 89fffd0

Please sign in to comment.