1 var Q = require('../kew')
3 // create a deferred which returns a promise
4 exports.testDeferredResolve = function (test) {
9 .then(function (data) {
10 test.equal(data, val, "Promise successfully returned")
14 setTimeout(function () {
19 // make sure a deferred can only resolve once
20 exports.testDeferredResolveOnce = function (test) {
26 test.fail("Unable to resolve the same deferred twice")
33 // create a deferred which returns a failed promise
34 exports.testDeferredReject = function (test) {
35 var err = new Error("hello")
40 test.equal(e, err, "Promise successfully failed")
44 setTimeout(function () {
49 // make sure a deferred can only reject once
50 exports.testDeferredRejectOnce = function (test) {
54 defer.reject(new Error("nope 1"))
55 defer.reject(new Error("nope 2"))
56 test.fail("Unable to reject the same deferred twice")
63 // make sure a deferred can only reject once
64 exports.testDeferAndRejectFail = function (test) {
69 defer.reject(new Error("nope 1"))
71 test.fail("Unable to reject and resolve the same deferred")
73 test.ok(true, "Unable to reject and resolve same deferred")
79 defer.reject(new Error("nope 1"))
80 test.fail("Unable to reject and resolve the same deferred")
82 test.ok(true, "Unable to reject and resolve same deferred")
88 // create a deferred which resolves with a node-standard callback
89 exports.testDeferredResolverSuccess = function (test) {
92 var callback = defer.makeNodeResolver()
95 .then(function (data) {
96 test.equal(data, val, "Promise successfully returned")
100 setTimeout(function () {
105 // create a deferred which rejects with a node-standard callback
106 exports.testDeferredResolverSuccess = function (test) {
107 var err = new Error("hello")
108 var defer = Q.defer()
109 var callback = defer.makeNodeResolver()
113 test.equal(e, err, "Promise successfully failed")
117 setTimeout(function () {