aboutsummaryrefslogtreecommitdiff
path: root/src/lib/utils/resolve_after.test.ts
blob: 4b30d3cc864ceb887a30f0cf72304f22329ed259 (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
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();
	});
});