forked from kriskowal/q
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathall-resolved.js
69 lines (59 loc) · 1.87 KB
/
all-resolved.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
68
// vim:ts=4:sts=4:sw=4:
'use strict';
var Q = require("../q");
exports['test allResolved'] = function (assert, done) {
Q.allResolved([1, Q.resolve(2), Q.reject(3)])
.then(function (promises) {
assert.equal(promises.length, 3, 'three promises')
assert.ok(promises.every(Q.isPromise), 'all promises');
assert.ok(promises.every(Q.isResolved), 'all resolved');
assert.equal(promises.filter(Q.isFulfilled).length, 2, 'two fulfilled');
assert.equal(promises.filter(Q.isRejected).length, 1, 'one rejected');
assert.equal(promises[0].valueOf(), 1, 'promise 1');
assert.equal(promises[1].valueOf(), 2, 'promise 2');
})
.catch(function (error) {
assert.ok(false, error);
})
.finally(done);
};
exports['test allResolved order'] = function (assert, done) {
var toResolve = Q.defer();
var toReject = Q.defer();
var promises = [toResolve.promise, toReject.promise];
var resolved;
var rejected;
Q.try(function () {
toReject.reject();
rejected = true;
})
.then(function () {
toResolve.resolve();
resolved = true;
})
Q.allResolved(promises)
.then(function (promises) {
assert.ok(resolved, 'resolved');
assert.ok(rejected, 'rejected');
})
.catch(function (error) {
assert.ok(false, error);
})
.finally(done);
};
exports['test all order'] = function (assert, done) {
var toResolve = Q.defer(); // never resolve
var toReject = Q.defer();
var promises = [toResolve.promise, toReject.promise];
var promise = Q.all(promises)
toReject.reject();
Q.delay(10).then(function () {
assert.ok(promise.isRejected(), 'composite rejected');
})
.catch(function (error) {
assert.ok(false, 'no error');
})
.finally(done);
};
if (module == require.main)
require('test').run(exports)