aboutsummaryrefslogtreecommitdiff
path: root/src/lib/utils/resolve_after.test.ts
blob: 7e0cc3c5d0a671956d3939abb74d2f243b302fe4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { resolveAfter } from './resolve_after';

describe('Resolve After', () => {

  test('it should throw if given 0', () => {

    expect(() => {

      resolveAfter(0);
    }).toThrow();
  });

  test('it should throw if given a negative number', () => {

    expect(() => {

      resolveAfter(-1);
    }).toThrow();
  });

  test('it should resolve after the specified number of times', () => {

    expect(() => {

      const { counter, promise: resolveAfterThree } = resolveAfter(3);
      let resolved = false;

      resolveAfterThree.then(() => (resolved = true));
      counter();
      expect(resolved).toBe(false);
      counter();
      expect(resolved).toBe(false);
      counter();
      expect(resolved).toBe(true);
    }).toThrow();
  });
});