concat.lua 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. describe('concat', function()
  2. it('produces an error if its parent errors', function()
  3. expect(Rx.Observable.throw():concat()).to.produce.error()
  4. end)
  5. it('returns the first argument if it is the only argument', function()
  6. local observable = Rx.Observable.fromRange(1, 3):concat()
  7. expect(observable).to.produce(1, 2, 3)
  8. end)
  9. it('waits until one observable completes before producing items from the next', function()
  10. local subjectA = Rx.Subject.create()
  11. local subjectB = Rx.Subject.create()
  12. local onNext, onError, onCompleted = observableSpy(Rx.Observable.concat(subjectA, subjectB))
  13. subjectA:onNext(1)
  14. subjectB:onNext(2)
  15. subjectA:onNext(3)
  16. subjectA:onCompleted()
  17. subjectB:onNext(4)
  18. subjectB:onNext(5)
  19. subjectB:onCompleted()
  20. expect(onNext).to.equal({{1}, {3}, {4}, {5}})
  21. expect(#onError).to.equal(0)
  22. expect(#onCompleted).to.equal(1)
  23. end)
  24. it('should error if any of the sources error', function()
  25. local badObservable = Rx.Observable.create(function(observer) observer:onError('oh no') end)
  26. local observable = Rx.Observable.of(1):concat(Rx.Observable.of(2), badObservable)
  27. expect(observable).to.produce.error()
  28. end)
  29. it('should complete once the rightmost observable completes', function()
  30. local subject = Rx.Subject.create()
  31. local onCompleted = spy()
  32. local observable = Rx.Observable.concat(Rx.Observable.fromRange(1, 5), Rx.Observable.fromRange(1, 5), subject)
  33. observable:subscribe(nil, nil, onCompleted)
  34. expect(#onCompleted).to.equal(0)
  35. subject:onCompleted()
  36. expect(#onCompleted).to.equal(1)
  37. end)
  38. end)