mirror of
https://github.com/bjc/prosody.git
synced 2025-04-03 21:27:38 +03:00
util.promise: Add some missing test cases (found through mutation testing)
This commit is contained in:
parent
a79238fb37
commit
e8080773d6
1 changed files with 25 additions and 0 deletions
|
@ -7,6 +7,11 @@ describe("util.promise", function ()
|
|||
assert(promise.new());
|
||||
end);
|
||||
end);
|
||||
it("supplies a sensible tostring()", function ()
|
||||
local s = tostring(promise.new());
|
||||
assert.truthy(s:find("promise", 1, true));
|
||||
assert.truthy(s:find("pending", 1, true));
|
||||
end);
|
||||
it("notifies immediately for fulfilled promises", function ()
|
||||
local p = promise.new(function (resolve)
|
||||
resolve("foo");
|
||||
|
@ -459,6 +464,26 @@ describe("util.promise", function ()
|
|||
{ status = "rejected", reason = "this fails" };
|
||||
}, result);
|
||||
end);
|
||||
it("works when all promises reject", function ()
|
||||
local r1, r2;
|
||||
local p1, p2 = promise.new(function (_, reject) r1 = reject end), promise.new(function (_, reject) r2 = reject end);
|
||||
local p = promise.all_settled({ p1, p2 });
|
||||
|
||||
local result;
|
||||
local cb = spy.new(function (v)
|
||||
result = v;
|
||||
end);
|
||||
p:next(cb);
|
||||
assert.spy(cb).was_called(0);
|
||||
r2("this fails");
|
||||
assert.spy(cb).was_called(0);
|
||||
r1("this fails too");
|
||||
assert.spy(cb).was_called(1);
|
||||
assert.same({
|
||||
{ status = "rejected", value = "this fails too" };
|
||||
{ status = "rejected", reason = "this fails" };
|
||||
}, result);
|
||||
end);
|
||||
it("works with non-numeric keys", function ()
|
||||
local r1, r2;
|
||||
local p1, p2 = promise.new(function (resolve) r1 = resolve end), promise.new(function (resolve) r2 = resolve end);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue