forked from kriskowal/q
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode.js
86 lines (77 loc) · 2.22 KB
/
node.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
"use strict";
var Q = require("../q");
var FS = require("fs"); // node
exports['test nbind (no arguments)'] = function (ASSERT, done) {
var readFile = Q.nbind(FS.readFile);
readFile(module.path || __filename, 'utf-8')
.then(function (content) {
ASSERT.equal(typeof content, "string", "readFile content");
})
.fail(function (reason) {
ASSERT.ok(false, reason);
})
.fin(done)
};
exports['test nbind (thisp only)'] = function (ASSERT, done) {
var that = {};
var artificial = Q.nbind(function (callback) {
callback(void 0, this);
}, that);
artificial()
.then(function (result) {
ASSERT.strictEqual(that, result, "this bound properly");
})
.fail(function (reason) {
ASSERT.ok(false, reason);
})
.fin(done)
};
exports['test nbind (thisp plus arguments)'] = function (ASSERT, done) {
var artificial = Q.nbind(function (value, callback) {
callback(void 0, value);
}, void 0, 10);
artificial()
.then(function (result) {
ASSERT.strictEqual(result, 10, "value partially applied");
})
.fail(function (reason) {
ASSERT.ok(false, reason);
})
.fin(done)
};
exports['test nbind error'] = function (ASSERT, done) {
var artificial = Q.nbind(function (callback) {
callback(new Error("bad"));
});
artificial()
.then(function (result) {
ASSERT.ok(false, "error forwarded");
})
.fail(function (reason) {
ASSERT.strictEqual(reason.message, "bad", "error forwarded");
})
.fin(done)
};
exports['test ncall'] = function (ASSERT, done) {
Q.ncall(FS.readFile, FS, module.path || __filename, 'utf-8')
.then(function (content) {
ASSERT.equal(typeof content, "string", "readFile content");
})
.fail(function (reason) {
ASSERT.ok(false, reason);
})
.fin(done)
};
exports['test napply'] = function (ASSERT, done) {
Q.napply(FS.readFile, FS, [module.path || __filename, 'utf-8'])
.then(function (content) {
ASSERT.equal(typeof content, "string", "readFile content");
})
.fail(function (reason) {
ASSERT.ok(false, reason);
})
.fin(done)
};
if (module == require.main) {
require('test').run(exports);
}