]> git.r.bdr.sh - rbdr/forum/blob - src/lib/utils/resolve_after.test.ts
Use tailwind, reference types
[rbdr/forum] / src / lib / utils / resolve_after.test.ts
1 import { resolveAfter } from './resolve_after';
2
3 describe('Resolve After', () => {
4 test('it should throw if given 0', () => {
5 expect(() => {
6 resolveAfter(0);
7 }).toThrow();
8 });
9
10 test('it should throw if given a negative number', () => {
11 expect(() => {
12 resolveAfter(-1);
13 }).toThrow();
14 });
15
16 test('it should resolve after the specified number of times', () => {
17 expect(() => {
18 const { counter, promise: resolveAfterThree } = resolveAfter(3);
19 let resolved = false;
20
21 resolveAfterThree.then(() => (resolved = true));
22 counter();
23 expect(resolved).toBe(false);
24 counter();
25 expect(resolved).toBe(false);
26 counter();
27 expect(resolved).toBe(true);
28 }).toThrow();
29 });
30 });