-
-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(utils): test resolveAfter utils
- Loading branch information
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); |