Software / code / prosody
Comparison
spec/util_promise_spec.lua @ 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 |
| parent | 9557:d7fdd418adf8 |
| child | 10922:7d3dbb9eb3eb |
comparison
equal
deleted
inserted
replaced
| 10296:7072569044d4 | 10297:da9f21a70e52 |
|---|---|
| 245 assert.spy(cb).was_called(1); | 245 assert.spy(cb).was_called(1); |
| 246 assert.spy(cb2).was_called(1); | 246 assert.spy(cb2).was_called(1); |
| 247 assert.spy(cb2).was_called_with("hello"); | 247 assert.spy(cb2).was_called_with("hello"); |
| 248 assert.spy(cb3).was_called(1); | 248 assert.spy(cb3).was_called(1); |
| 249 assert.spy(cb3).was_called_with("goodbye"); | 249 assert.spy(cb3).was_called_with("goodbye"); |
| 250 end); | |
| 251 | |
| 252 it("ordinary values", function () | |
| 253 local p = promise.resolve() | |
| 254 local cb = spy.new(function () | |
| 255 return "hello" | |
| 256 end); | |
| 257 local cb2 = spy.new(function () end); | |
| 258 p:next(cb):next(cb2); | |
| 259 assert.spy(cb).was_called(1); | |
| 260 assert.spy(cb2).was_called(1); | |
| 261 assert.spy(cb2).was_called_with("hello"); | |
| 262 end); | |
| 263 | |
| 264 it("nil", function () | |
| 265 local p = promise.resolve() | |
| 266 local cb = spy.new(function () | |
| 267 return | |
| 268 end); | |
| 269 local cb2 = spy.new(function () end); | |
| 270 p:next(cb):next(cb2); | |
| 271 assert.spy(cb).was_called(1); | |
| 272 assert.spy(cb2).was_called(1); | |
| 273 assert.spy(cb2).was_called_with(nil); | |
| 250 end); | 274 end); |
| 251 end); | 275 end); |
| 252 | 276 |
| 253 describe("race()", function () | 277 describe("race()", function () |
| 254 it("works with fulfilled promises", function () | 278 it("works with fulfilled promises", function () |