aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2021-03-25 14:32:32 +0000
committerMatthew Wild <mwild1@gmail.com>2021-03-25 14:32:32 +0000
commitfec0d44e89f58dae50063be87a6d9360e012f205 (patch)
tree2bec243fb99a039d6dc2a24638711926c65fe23f /spec
parent2141d9d94a7b0c855a99e4444b093f80ee316f75 (diff)
downloadprosody-fec0d44e89f58dae50063be87a6d9360e012f205.tar.gz
prosody-fec0d44e89f58dae50063be87a6d9360e012f205.zip
util.promise: all()/all_settled() pass through non-promise values
Diffstat (limited to 'spec')
-rw-r--r--spec/util_promise_spec.lua33
1 files changed, 33 insertions, 0 deletions
diff --git a/spec/util_promise_spec.lua b/spec/util_promise_spec.lua
index 79eec5e2..f64702bf 100644
--- a/spec/util_promise_spec.lua
+++ b/spec/util_promise_spec.lua
@@ -369,6 +369,21 @@ describe("util.promise", function ()
assert.spy(cb).was_called(1);
assert.same({ [true] = "nope", [false] = "yep" }, result);
end);
+ it("passes through non-promise values", function ()
+ local r1;
+ local p1 = promise.new(function (resolve) r1 = resolve end);
+ local p = promise.all({ [true] = p1, [false] = "yep" });
+
+ local result;
+ local cb = spy.new(function (v)
+ result = v;
+ end);
+ p:next(cb);
+ assert.spy(cb).was_called(0);
+ r1("nope");
+ assert.spy(cb).was_called(1);
+ assert.same({ [true] = "nope", [false] = "yep" }, result);
+ end);
end);
describe("all_settled()", function ()
it("works with fulfilled promises", function ()
@@ -443,6 +458,24 @@ describe("util.promise", function ()
bar = { status = "fulfilled", value = "yep" };
}, result);
end);
+ it("passes through non-promise values", function ()
+ local r1;
+ local p1 = promise.new(function (resolve) r1 = resolve end);
+ local p = promise.all_settled({ foo = p1, bar = "yep" });
+
+ local result;
+ local cb = spy.new(function (v)
+ result = v;
+ end);
+ p:next(cb);
+ assert.spy(cb).was_called(0);
+ r1("nope");
+ assert.spy(cb).was_called(1);
+ assert.same({
+ foo = { status = "fulfilled", value = "nope" };
+ bar = "yep";
+ }, result);
+ end);
end);
describe("catch()", function ()
it("works", function ()