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