Skip to content

Commit 57cad9c

Browse files
committed
Add tests for promises.promisify()
1 parent 23fd51d commit 57cad9c

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

test/promises.tests.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,50 @@ test("nfcall", {
208208
}
209209
});
210210

211+
test("promisify", {
212+
"when function throws error then promise is rejected": function() {
213+
return promises.promisify(function() {
214+
throw new Error("failure");
215+
})().then(
216+
function() {
217+
assert.fail("Expected rejection");
218+
},
219+
function(error) {
220+
assert.strictEqual(error.message, "failure");
221+
}
222+
);
223+
},
224+
225+
"when function calls callback with error then promise is rejected": function() {
226+
return promises.promisify(function(callback) {
227+
callback(new Error("failure"));
228+
})().then(
229+
function() {
230+
assert.fail("Expected rejection");
231+
},
232+
function(error) {
233+
assert.strictEqual(error.message, "failure");
234+
}
235+
);
236+
},
237+
238+
"when function calls callback with value then promise is resolved": function() {
239+
return promises.promisify(function(callback) {
240+
callback(null, "success");
241+
})().then(function(result) {
242+
assert.strictEqual(result, "success");
243+
});
244+
},
245+
246+
"function is called with passed arguments": function() {
247+
return promises.promisify(function(a, b, callback) {
248+
callback(null, ["success", a, b]);
249+
})("a", "b").then(function(result) {
250+
assert.deepStrictEqual(result, ["success", "a", "b"]);
251+
});
252+
}
253+
});
254+
211255
test("props", {
212256
"props({}) resolve to {}": function() {
213257
return promises.props({}).then(function(result) {

0 commit comments

Comments
 (0)