Skip to content

Commit 5a3a285

Browse files
committed
Add tests for promises.nfcall()
1 parent 1daa6ef commit 5a3a285

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

test/promises.tests.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,37 @@ test("forEachSeries", {
164164
}
165165
});
166166

167+
test("nfcall", {
168+
"when function calls callback with error then promise is rejected": function() {
169+
return promises.nfcall(function(callback) {
170+
callback(new Error("failure"));
171+
}).then(
172+
function(result) {
173+
assert.fail("Expected rejection");
174+
},
175+
function(error) {
176+
assert.strictEqual(error.message, "failure");
177+
}
178+
);
179+
},
180+
181+
"when function calls callback with value then promise is resolved": function() {
182+
return promises.nfcall(function(callback) {
183+
callback(null, "success");
184+
}).then(function(result) {
185+
assert.strictEqual(result, "success");
186+
});
187+
},
188+
189+
"function is called with passed arguments": function() {
190+
return promises.nfcall(function(a, b, callback) {
191+
callback(null, ["success", a, b]);
192+
}, "a", "b").then(function(result) {
193+
assert.deepStrictEqual(result, ["success", "a", "b"]);
194+
});
195+
}
196+
});
197+
167198
test("props", {
168199
"props({}) resolve to {}": function() {
169200
return promises.props({}).then(function(result) {

0 commit comments

Comments
 (0)