@util.js/promises 0.41.4 → 0.41.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/doc/README-examples.js +1 -1
- package/lib/Promises.js +4 -4
- package/package.json +1 -2
- package/test/PromisesTest.js +21 -21
package/README.md
CHANGED
package/doc/README-examples.js
CHANGED
package/lib/Promises.js
CHANGED
|
@@ -176,13 +176,13 @@ class Promises {
|
|
|
176
176
|
if (returnValue) return returnValue;
|
|
177
177
|
if (typeof promiseFunction !== "function")
|
|
178
178
|
throw new TypeError(
|
|
179
|
-
`We expected promiseFunction to be function, but it was ${promiseFunction}
|
|
179
|
+
`We expected promiseFunction to be function, but it was ${promiseFunction}.`,
|
|
180
180
|
);
|
|
181
181
|
returnValue = function (...args) {
|
|
182
182
|
const callback = arguments[args.length - 1];
|
|
183
183
|
if (typeof callback !== "function")
|
|
184
184
|
throw new TypeError(
|
|
185
|
-
`We expected callback to be a function, but it was ${callback}
|
|
185
|
+
`We expected callback to be a function, but it was ${callback}.`,
|
|
186
186
|
);
|
|
187
187
|
const argsWithoutCalback = Array.from(args).slice(0, args.length - 1);
|
|
188
188
|
let promise;
|
|
@@ -193,7 +193,7 @@ class Promises {
|
|
|
193
193
|
}
|
|
194
194
|
if (!promise && !promise.then)
|
|
195
195
|
throw new Error(
|
|
196
|
-
`We expected promiseFunction to return a Promise but instead got ${promise}
|
|
196
|
+
`We expected promiseFunction to return a Promise but instead got ${promise}.`,
|
|
197
197
|
);
|
|
198
198
|
promise.then((result) => callback(null, result)).catch(callback);
|
|
199
199
|
// It is possible for the callback to throw an error.
|
|
@@ -303,7 +303,7 @@ class Promises {
|
|
|
303
303
|
if (returnValue) return returnValue;
|
|
304
304
|
if (typeof functionWithCallback !== "function")
|
|
305
305
|
throw new TypeError(
|
|
306
|
-
`We expected functionWithCallback to be a function, but it was ${functionWithCallback}
|
|
306
|
+
`We expected functionWithCallback to be a function, but it was ${functionWithCallback}.`,
|
|
307
307
|
);
|
|
308
308
|
returnValue = function (...args) {
|
|
309
309
|
const thiz = this;
|
package/package.json
CHANGED
package/test/PromisesTest.js
CHANGED
|
@@ -12,24 +12,24 @@ describe("Promises", function () {
|
|
|
12
12
|
}
|
|
13
13
|
it("should resolve a Promise", async function () {
|
|
14
14
|
expect(
|
|
15
|
-
await promises.applyCallback(null, notify, ["Promise me", "Hypnotoad"])
|
|
15
|
+
await promises.applyCallback(null, notify, ["Promise me", "Hypnotoad"]),
|
|
16
16
|
).to.eql("Promise me, Hypnotoad!");
|
|
17
17
|
expect(
|
|
18
|
-
await promises.callCallback(null, notify, "Promise me", "Hypnotoad")
|
|
18
|
+
await promises.callCallback(null, notify, "Promise me", "Hypnotoad"),
|
|
19
19
|
).to.eql("Promise me, Hypnotoad!");
|
|
20
20
|
});
|
|
21
21
|
it("should error if functionOnObjectWithCallback is not a function", () => {
|
|
22
22
|
expect(() =>
|
|
23
|
-
promises.applyCallback(null, null, ["Promise me", "Hypnotoad"])
|
|
23
|
+
promises.applyCallback(null, null, ["Promise me", "Hypnotoad"]),
|
|
24
24
|
).to.throw(TypeError);
|
|
25
25
|
expect(() =>
|
|
26
|
-
promises.callCallback(null, null, "Promise me", "Hypnotoad")
|
|
26
|
+
promises.callCallback(null, null, "Promise me", "Hypnotoad"),
|
|
27
27
|
).to.throw(TypeError);
|
|
28
28
|
expect(() =>
|
|
29
|
-
promises.applyCallback(null, "a", ["Promise me", "Hypnotoad"])
|
|
29
|
+
promises.applyCallback(null, "a", ["Promise me", "Hypnotoad"]),
|
|
30
30
|
).to.throw(TypeError);
|
|
31
31
|
expect(() =>
|
|
32
|
-
promises.callCallback(null, "a", "Promise me", "Hypnotoad")
|
|
32
|
+
promises.callCallback(null, "a", "Promise me", "Hypnotoad"),
|
|
33
33
|
).to.throw(TypeError);
|
|
34
34
|
});
|
|
35
35
|
it("should error if args is erroneous", () => {
|
|
@@ -97,7 +97,7 @@ describe("Promises", function () {
|
|
|
97
97
|
}
|
|
98
98
|
expect(message).to.eql("Call back, Hypnotoad!");
|
|
99
99
|
c(callbck);
|
|
100
|
-
}
|
|
100
|
+
},
|
|
101
101
|
);
|
|
102
102
|
}
|
|
103
103
|
function c(callbck) {
|
|
@@ -121,22 +121,22 @@ describe("Promises", function () {
|
|
|
121
121
|
} catch (err) {
|
|
122
122
|
callbck(err);
|
|
123
123
|
}
|
|
124
|
-
}
|
|
124
|
+
},
|
|
125
125
|
);
|
|
126
126
|
}
|
|
127
127
|
});
|
|
128
128
|
it("should error if promiseFunction is not a function", () => {
|
|
129
129
|
expect(() =>
|
|
130
|
-
promises.applyPromise(null, null, ["Call back", "Hypnotoad"])
|
|
130
|
+
promises.applyPromise(null, null, ["Call back", "Hypnotoad"]),
|
|
131
131
|
).to.throw(TypeError);
|
|
132
132
|
expect(() =>
|
|
133
|
-
promises.callPromise(null, null, "Call back", "Hypnotoad")
|
|
133
|
+
promises.callPromise(null, null, "Call back", "Hypnotoad"),
|
|
134
134
|
).to.throw(TypeError);
|
|
135
135
|
expect(() =>
|
|
136
|
-
promises.applyPromise(null, "a", ["Call back", "Hypnotoad"])
|
|
136
|
+
promises.applyPromise(null, "a", ["Call back", "Hypnotoad"]),
|
|
137
137
|
).to.throw(TypeError);
|
|
138
138
|
expect(() =>
|
|
139
|
-
promises.callPromise(null, "a", "Call back", "Hypnotoad")
|
|
139
|
+
promises.callPromise(null, "a", "Call back", "Hypnotoad"),
|
|
140
140
|
).to.throw(TypeError);
|
|
141
141
|
});
|
|
142
142
|
it("should handle erroneous input", (callback) => {
|
|
@@ -219,11 +219,11 @@ describe("Promises", function () {
|
|
|
219
219
|
callback(
|
|
220
220
|
new Error(
|
|
221
221
|
"We expected #callPromise to not call this callback.",
|
|
222
|
-
{ cause: error }
|
|
223
|
-
)
|
|
222
|
+
{ cause: error },
|
|
223
|
+
),
|
|
224
224
|
);
|
|
225
|
-
}
|
|
226
|
-
)
|
|
225
|
+
},
|
|
226
|
+
),
|
|
227
227
|
).to.throw(Error);
|
|
228
228
|
callbck();
|
|
229
229
|
} catch (error) {
|
|
@@ -298,20 +298,20 @@ describe("Promises", function () {
|
|
|
298
298
|
cb();
|
|
299
299
|
}
|
|
300
300
|
expect(() => promises.applyCallback(null, functionWithCallback)).to.throw(
|
|
301
|
-
TypeError
|
|
301
|
+
TypeError,
|
|
302
302
|
);
|
|
303
303
|
expect(() =>
|
|
304
|
-
promises.applyCallback(null, functionWithCallback, null)
|
|
304
|
+
promises.applyCallback(null, functionWithCallback, null),
|
|
305
305
|
).to.throw(TypeError);
|
|
306
306
|
// The following line sends functionWithCallback the wrong number of arguments.
|
|
307
307
|
expect(() =>
|
|
308
|
-
promises.applyCallback(null, functionWithCallback, "a")
|
|
308
|
+
promises.applyCallback(null, functionWithCallback, "a"),
|
|
309
309
|
).to.throw(TypeError);
|
|
310
310
|
expect(() => promises.applyCallback(null, null, [() => {}])).to.throw(
|
|
311
|
-
TypeError
|
|
311
|
+
TypeError,
|
|
312
312
|
);
|
|
313
313
|
expect(() => promises.applyCallback(null, "a", [() => {}])).to.throw(
|
|
314
|
-
TypeError
|
|
314
|
+
TypeError,
|
|
315
315
|
);
|
|
316
316
|
expect(() => promises.applyCallback(null, null, [])).to.throw(TypeError);
|
|
317
317
|
expect(() => promises.applyCallback(null, "a", [])).to.throw(TypeError);
|