-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
67 lines (49 loc) · 2.04 KB
/
index.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { describe, it } from 'node:test';
import { strict as assert } from 'node:assert';
import Deferred from 'es2015-deferred';
describe('Deferred', () => {
it('is a function', () => {
assert.equal(typeof Deferred, 'function');
});
it('returns an instance of Deferred when called with new', () => {
assert.ok(new Deferred() instanceof Deferred);
});
it('returns an instance of Deferred when called without new', () => {
assert.ok(Deferred() instanceof Deferred); // eslint-disable-line new-cap
});
describe('an instance', () => {
it('has a promise property, which is an instance of Promise', () => {
assert.ok(new Deferred().promise instanceof Promise);
});
it('has a resolve property, which is a method', () => {
assert.equal(typeof new Deferred().resolve, 'function');
});
it('has a reject property, which is a method', () => {
assert.equal(typeof new Deferred().reject, 'function');
});
it('resolves the promise property with a value when the resolve property is called with that value', async () => {
const deferred = new Deferred();
deferred.resolve('resolution-value');
const value = await deferred.promise;
assert.equal(value, 'resolution-value');
});
it('returns the promise from the resolve method', () => {
const deferred = new Deferred();
assert.equal(deferred.resolve('resolution-value'), deferred.promise);
});
it('rejects the promise property with a value when the reject property is called with that value', () => {
const deferred = new Deferred();
deferred.reject('rejection-value');
return deferred.promise
.then(
() => assert.end(new Error('Promise should not resolve')),
value => assert.equal(value, 'rejection-value')
);
});
it('returns the promise from the reject method', () => {
const deferred = new Deferred();
assert.equal(deferred.reject('rejection-value'), deferred.promise);
return deferred.promise.catch(() => {});
});
});
});