catch.lua 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. describe('catch', function()
  2. it('ignores errors if no handler is specified', function()
  3. expect(Rx.Observable.throw():catch()).to.produce.nothing()
  4. end)
  5. it('continues producing values from the specified observable if the source errors', function()
  6. local handler = Rx.Subject.create()
  7. local observable = Rx.Observable.create(function(observer)
  8. observer:onNext(1)
  9. observer:onNext(2)
  10. observer:onError('ohno')
  11. observer:onNext(3)
  12. observer:onCompleted()
  13. end)
  14. handler:onNext(5)
  15. local onNext = observableSpy(observable:catch(handler))
  16. handler:onNext(6)
  17. handler:onNext(7)
  18. handler:onCompleted()
  19. expect(onNext).to.equal({{1}, {2}, {6}, {7}})
  20. end)
  21. it('allows a function as an argument', function()
  22. local handler = function() return Rx.Observable.empty() end
  23. expect(Rx.Observable.throw():catch(handler)).to.produce.nothing()
  24. end)
  25. it('calls onError if the supplied function errors', function()
  26. local handler = error
  27. local onError = spy()
  28. Rx.Observable.throw():catch(handler):subscribe(nil, onError, nil)
  29. expect(#onError).to.equal(1)
  30. end)
  31. it('calls onComplete when the parent completes', function()
  32. local onComplete = spy()
  33. Rx.Observable.throw():catch():subscribe(nil, nil, onComplete)
  34. expect(#onComplete).to.equal(1)
  35. end)
  36. end)