aboutsummaryrefslogtreecommitdiffstats
path: root/spec/util_promise_spec.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2018-10-25 15:24:52 +0100
committerMatthew Wild <mwild1@gmail.com>2018-10-25 15:24:52 +0100
commite6ff6e333ce7726e187d5f5ca30a0796dbe717a9 (patch)
treec362a3c6ca2861d61f457879b4b2a028257f9f89 /spec/util_promise_spec.lua
parentb74a643e349651c8161512c3180c32da7c6665c0 (diff)
downloadprosody-e6ff6e333ce7726e187d5f5ca30a0796dbe717a9.tar.gz
prosody-e6ff6e333ce7726e187d5f5ca30a0796dbe717a9.zip
util.promise: Fix missing parameters
Diffstat (limited to 'spec/util_promise_spec.lua')
-rw-r--r--spec/util_promise_spec.lua30
1 files changed, 28 insertions, 2 deletions
diff --git a/spec/util_promise_spec.lua b/spec/util_promise_spec.lua
index a06232b1..90043346 100644
--- a/spec/util_promise_spec.lua
+++ b/spec/util_promise_spec.lua
@@ -142,7 +142,7 @@ describe("util.promise", function ()
local r, result;
local test_error = {};
local p = promise.new(function (resolve, reject)
- r = resolve;
+ r = reject;
end);
local cb = spy.new(function () end);
local err_cb = spy.new(function (e) result = e end);
@@ -154,7 +154,8 @@ describe("util.promise", function ()
r("oh doh");
assert.spy(cb).was_called(0);
assert.spy(err_cb).was_called(1);
- assert.equal(test_error, result);
+ assert.spy(err_cb).was_called_with("oh doh");
+ assert.equal("oh doh", result);
end);
it("propagates values down the chain, even when some handlers are not provided", function ()
@@ -175,6 +176,31 @@ describe("util.promise", function ()
assert.spy(err_cb).was_called(0);
end);
+ it("fulfilled promises do not call error handlers and do propagate value", function ()
+ local p = promise.resolve("foo");
+ local cb = spy.new(function () end);
+ local p2 = p:catch(cb);
+ assert.spy(cb).was_called(0);
+
+ local cb2 = spy.new(function () end);
+ local p3 = p2:catch(cb2);
+ assert.spy(cb2).was_called(0);
+ end);
+
+ it("rejected promises do not call fulfilled handlers and do propagate reason", function ()
+ local p = promise.reject("foo");
+ local cb = spy.new(function () end);
+ local p2 = p:next(cb);
+ assert.spy(cb).was_called(0);
+
+ local cb2 = spy.new(function () end);
+ local cb2_err = spy.new(function () end);
+ local p3 = p2:next(cb2, cb2_err);
+ assert.spy(cb2).was_called(0);
+ assert.spy(cb2_err).was_called(1);
+ assert.spy(cb2_err).was_called_with("foo");
+ end);
+
describe("race()", function ()
it("works with fulfilled promises", function ()
local p1, p2 = promise.resolve("yep"), promise.resolve("nope");