aboutsummaryrefslogtreecommitdiff
path: root/src/utils/resolve_after.test.js
blob: f7fc75364d85542f4d12cf5f895e9c94784d683a (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
38
39
40
41
42
43
44
45
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 throw if given a negative number', () => {

    expect(() => {

      resolveAfter('lol');
    }).toThrow();
  });

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

    expect(() => {

      const { counter, 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();
  });
});