-
Notifications
You must be signed in to change notification settings - Fork 0
/
LagouPromise.spec.js
53 lines (45 loc) · 1.42 KB
/
LagouPromise.spec.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
/* global describe, it, expect */
/* eslint prefer-arrow-callback:0, func-names:0 */
/* eslint no-unused-vars: ["error", { "argsIgnorePattern": "^_" }] */
const LagouPromise = require('./lib/LagouPromise').default;
describe('Promises', function () {
it('should resolve', function () {
new LagouPromise(function (resolve) {
resolve(42);
}).then(function (value) {
expect(value).toEqual(42);
});
});
it('should chain', function () {
new LagouPromise(function (resolve) {
resolve(42);
}).then(function (value) {
return value + 1;
}).then(function (value) {
expect(value).toEqual(43);
});
});
it('should recover', function () {
new LagouPromise(function (_resolve) {
throw new Error();
}).then(null, function (_error) {
return 42;
}).then(function (value) {
expect(value).toEqual(42);
});
});
it('should handle promises being resolved with other promises', function () {
const innerPromise = new LagouPromise(resolve => resolve(42));
const outerPromise = new LagouPromise(resolve => resolve(innerPromise));
outerPromise.then(value => expect(value).toEqual(42));
});
it('should not allow fulfilling or rejecting twice', function () {
let resolver;
const promise = new LagouPromise(r => {
resolver = r;
});
resolver('foo');
resolver('bar');
promise.then(v => expect(v).toEqual('foo'));
});
});