elementAt.lua 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. describe('elementAt', function()
  2. it('errors when its parent errors', function()
  3. expect(Rx.Observable.throw():elementAt(1).subscribe).to.fail()
  4. end)
  5. it('chains subscriptions', function()
  6. local subscription = Rx.Subscription.create()
  7. local observable = Rx.Observable.create(function() return subscription end)
  8. expect(observable:subscribe()).to.equal(subscription)
  9. expect(observable:elementAt(1):subscribe()).to.equal(subscription)
  10. end)
  11. it('errors if no index is specified', function()
  12. expect(Rx.Observable.fromValue(1):elementAt().subscribe).to.fail()
  13. end)
  14. it('produces no values if the specified index is less than one', function()
  15. expect(Rx.Observable.fromValue(1):elementAt(0)).to.produce.nothing()
  16. expect(Rx.Observable.fromValue(1):elementAt(-1)).to.produce.nothing()
  17. end)
  18. it('produces no values if the specified index is greater than the number of elements produced by the source', function()
  19. expect(Rx.Observable.fromValue(1):elementAt(2)).to.produce.nothing()
  20. end)
  21. it('produces all values produced by the source at the specified index', function()
  22. local observable = Rx.Observable.create(function(observer)
  23. observer:onNext(1, 2, 3)
  24. observer:onNext(4, 5, 6)
  25. observer:onCompleted()
  26. end)
  27. expect(observable:elementAt(2)).to.produce({{4, 5, 6}})
  28. end)
  29. end)