Skip to content

Commit 5913432

Browse files
jugglinmiketbranyen
authored andcommitted
Add tests for asynchronous method inference
1 parent 3a72e0f commit 5913432

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

test/index.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,54 @@ describe("Promisify", function() {
1717
it("exports a callbacks array", function() {
1818
assert(Array.isArray(promisify.callbacks));
1919
});
20+
21+
describe("asynchronous method inference", function() {
22+
var later = function(cb) {
23+
setTimeout(cb(null), 0);
24+
};
25+
26+
it("does not modify methods that do not appear to be asynchronous", function() {
27+
var obj = {
28+
a: function(probably, not, async) {}
29+
};
30+
var wrappedObj = promisify(obj);
31+
32+
assert.equal(
33+
obj.a,
34+
wrappedObj.a
35+
);
36+
});
37+
38+
it("can infer callback-accepting functions by argument list", function() {
39+
var obj = promisify({
40+
a: function(cb) { later(cb); }
41+
});
42+
43+
return obj.a();
44+
});
45+
46+
it("can infer callback-accepting functions by argument list", function() {
47+
var obj = promisify({
48+
a: function(callback) { later(callback); }
49+
});
50+
51+
return obj.a();
52+
});
53+
54+
it("can infer callback-accepting functions by argument list", function() {
55+
var obj = promisify({
56+
a: function(callback_) { later(callback_); }
57+
});
58+
59+
return obj.a();
60+
});
61+
62+
it("can infer callback-accepting functions by argument list", function() {
63+
var obj = promisify({
64+
a: function(done) { later(done); }
65+
});
66+
67+
return obj.a();
68+
});
69+
});
2070
});

0 commit comments

Comments
 (0)