-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnewPromiseHandle.test.js
47 lines (41 loc) · 1.06 KB
/
newPromiseHandle.test.js
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
46
47
'use strict';
const subject = require('./newPromiseHandle');
const test = require('ava');
test('Handle has expected keys', t => {
const handle = subject();
t.truthy(handle.promise);
t.truthy(handle.resolve);
t.truthy(handle.reject);
});
test('Promise resolves as expected', async t => {
const handle = subject();
const expected = 'resolve';
handle.resolve(expected);
const actual = await handle.promise;
t.is(actual, expected);
});
test('Promise rejects as expected', async t => {
const handle = subject();
const expected = 'reject';
handle.reject(expected);
try {
await handle.promise;
} catch (actual) {
t.is(actual, expected);
}
});
test('Reject returns rejected promise', async t => {
const handle = subject();
const expected = 'reject';
try {
await handle.reject(expected);
} catch (actual) {
t.is(actual, expected);
}
});
test('Resolve returns resolved promise', async t => {
const handle = subject();
const expected = 'resolve';
const actual = await handle.resolve(expected);
t.is(actual, expected);
});