Debian Codegraph @

deferred/test/ext/promise/invoke-async.js

raw
1 "use strict";
2
3 var deferred = require("../../../deferred");
4
5 module.exports = function () {
6 return {
7 "Function": function (a, d) {
8 var x = {}, z = {};
9 z.foo = function (y, cb) {
10 var self = this;
11 setTimeout(function () { cb(null, self, y); }, 0);
12 return 3;
13 };
14 deferred(z).invokeAsync("foo", x)(function (r) { a.deep(r, [z, x]); }).done(d, d);
15 },
16 "Method": function (a, d) {
17 var x = {}, fn, z = {};
18 fn = function (y, cb) {
19 var self = this;
20 setTimeout(function () { cb(null, self, y); }, 0);
21 return 3;
22 };
23 deferred(z).invokeAsync(fn, x)(function (r) { a.deep(r, [z, x]); }).done(d, d);
24 },
25 "Fail": function (a) {
26 var e = new Error("Error");
27 deferred(e).invokeAsync("bla")(a.never, function (r) { a(r, e); }).done();
28 },
29 "Null input": function (a) {
30 deferred(null)
31 .invokeAsync("test")(a.never, function (e) { a.ok(e instanceof TypeError); })
32 .done();
33 },
34 "No Function": function (a) {
35 deferred({})
36 .invokeAsync("test")(a.never, function (e) { a.ok(e instanceof TypeError); })
37 .done();
38 },
39 "Promise arguments": function (a) {
40 var y = {}
41 , z = {}
42 , x = {
43 foo: function (w, u, cb) {
44 a(this, x, "Context");
45 a.deep([w, u], [y, z], "Arguments");
46 cb(null, "foo");
47 }
48 };
49 deferred(x)
50 .invokeAsync("foo", deferred(y), z)(function (r) {
51 a(r, "foo", "Result");
52 }, a.never)
53 .done();
54 },
55 "Erroneous": function (a, d) {
56 var x, fn;
57 x = new Error("Test");
58 fn = function (callback) {
59 setTimeout(function () { callback(x); }, 0);
60 };
61 deferred({}).invokeAsync(fn)(a.never, function (e) { a(e, x); }).done(d, d);
62 },
63 "Function crash": function (a) {
64 var x = new Error("Test"), fn;
65 fn = function () { throw x; };
66 deferred({}).invokeAsync(fn)(a.never, function (e) { a(e, x); }).done();
67 }
68 };
69 };