switch.lua 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. describe('switch', function()
  2. it('errors when the source errors', function()
  3. expect(Rx.Observable.throw():switch().subscribe).to.fail()
  4. end)
  5. it('errors when an Observable produced by the source errors', function()
  6. local observable = Rx.Observable.create(function(observer)
  7. observer:onNext(Rx.Observable.throw())
  8. observer:onCompleted()
  9. end)
  10. expect(observable:switch().subscribe).to.fail()
  11. end)
  12. it('produces the values produced by the latest Observable produced by the source', function()
  13. local a = Rx.Subject.create()
  14. local b = Rx.Subject.create()
  15. local c = Rx.Subject.create()
  16. local onNext, onError, onCompleted = observableSpy(a:switch())
  17. b:onNext(1)
  18. a:onNext(b)
  19. b:onNext(2)
  20. b:onNext(3)
  21. c:onNext(7)
  22. a:onNext(c)
  23. b:onNext(4)
  24. c:onNext(8)
  25. b:onCompleted()
  26. c:onNext(9)
  27. c:onCompleted()
  28. a:onCompleted()
  29. expect(onNext).to.equal({{2}, {3}, {8}, {9}})
  30. expect(#onError).to.equal(0)
  31. expect(#onCompleted).to.equal(1)
  32. end)
  33. end)