flatMap.lua 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. describe('flatMap', function()
  2. it('produces an error if its parent errors', function()
  3. local observable = Rx.Observable.of(''):flatMap(function(x) return x() end)
  4. expect(observable).to.produce.error()
  5. end)
  6. it('uses the identity function as the callback if none is specified', function()
  7. local observable = Rx.Observable.fromTable{
  8. Rx.Observable.fromRange(3),
  9. Rx.Observable.fromRange(5)
  10. }:flatMap()
  11. expect(observable).to.produce(1, 2, 3, 1, 2, 3, 4, 5)
  12. end)
  13. it('produces all values produced by the observables produced by its parent', function()
  14. local observable = Rx.Observable.fromRange(3):flatMap(function(i)
  15. return Rx.Observable.fromRange(i, 3)
  16. end)
  17. expect(observable).to.produce(1, 2, 3, 2, 3, 3)
  18. end)
  19. it('completes after all observables produced by its parent', function()
  20. s = Rx.CooperativeScheduler.create()
  21. local observable = Rx.Observable.fromRange(3):flatMap(function(i)
  22. return Rx.Observable.fromRange(i, 3):delay(i, s)
  23. end)
  24. local onNext, onError, onCompleted, order = observableSpy(observable)
  25. repeat s:update(1)
  26. until s:isEmpty()
  27. expect(#onNext).to.equal(6)
  28. expect(#onCompleted).to.equal(1)
  29. end)
  30. end)