concat.lua 1.6 KB

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