Changeset

10297:da9f21a70e52

util.promise: Add some additional tests to cover callback return values
author Matthew Wild <mwild1@gmail.com>
date Mon, 30 Sep 2019 08:22:30 +0100
parents 10296:7072569044d4
children 10299:fd94721186b8
files spec/util_promise_spec.lua
diffstat 1 files changed, 24 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/spec/util_promise_spec.lua	Sun Sep 29 23:50:34 2019 +0200
+++ b/spec/util_promise_spec.lua	Mon Sep 30 08:22:30 2019 +0100
@@ -248,6 +248,30 @@
 			assert.spy(cb3).was_called(1);
 			assert.spy(cb3).was_called_with("goodbye");
 		end);
+
+		it("ordinary values", function ()
+			local p = promise.resolve()
+			local cb = spy.new(function ()
+				return "hello"
+			end);
+			local cb2 = spy.new(function () end);
+			p:next(cb):next(cb2);
+			assert.spy(cb).was_called(1);
+			assert.spy(cb2).was_called(1);
+			assert.spy(cb2).was_called_with("hello");
+		end);
+
+		it("nil", function ()
+			local p = promise.resolve()
+			local cb = spy.new(function ()
+				return
+			end);
+			local cb2 = spy.new(function () end);
+			p:next(cb):next(cb2);
+			assert.spy(cb).was_called(1);
+			assert.spy(cb2).was_called(1);
+			assert.spy(cb2).was_called_with(nil);
+		end);
 	end);
 
 	describe("race()", function ()