| 1 | var Q = require('../kew') |
| 2 | |
| 3 | exports.testSpreadStatic = function (test) { |
| 4 | Q.spread([Q.resolve('a'), 'b'], function (a, b) { |
| 5 | test.equal('a', a) |
| 6 | test.equal('b', b) |
| 7 | test.done() |
| 8 | }) |
| 9 | } |
| 10 | |
| 11 | exports.testSpreadMethod = function (test) { |
| 12 | Q.resolve(true) |
| 13 | .then(function () { |
| 14 | return ['a', 'b'] |
| 15 | }) |
| 16 | .spread(function (a, b) { |
| 17 | test.equal('a', a) |
| 18 | test.equal('b', b) |
| 19 | test.done() |
| 20 | }) |
| 21 | } |
| 22 | |
| 23 | exports.testSpreadBoundMethod = function (test) { |
| 24 | Q.resolve(true) |
| 25 | .then(function () { |
| 26 | return [Q.resolve('a'), 'b'] |
| 27 | }) |
| 28 | .spreadBound(function (c, a, b) { |
| 29 | test.equal('scope', this.scope) |
| 30 | test.equal('c', c) |
| 31 | test.equal('a', a) |
| 32 | test.equal('b', b) |
| 33 | test.done() |
| 34 | }, {scope: 'scope'}, 'c') |
| 35 | } |
| 36 | |
| 37 | exports.testAllSynchronization1 = function (test) { |
| 38 | var order = [] |
| 39 | Q.resolve(true) |
| 40 | .then(function () { |
| 41 | var promiseA = Q.fcall(function () { |
| 42 | order.push('a') |
| 43 | }) |
| 44 | var promiseB = Q.fcall(function () { |
| 45 | order.push('b') |
| 46 | }) |
| 47 | |
| 48 | test.deepEqual([], order) |
| 49 | |
| 50 | var promiseAB = Q.all([promiseA, promiseB]) |
| 51 | test.deepEqual([], order) |
| 52 | |
| 53 | return [promiseA, promiseB] |
| 54 | }) |
| 55 | .then(function (results) { |
| 56 | test.deepEqual(['a', 'b'], order) |
| 57 | test.done() |
| 58 | }) |
| 59 | } |