with.lua 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. describe('with', function()
  2. it('returns the observable it is called on if no other sources are specified', function()
  3. local observable = Rx.Observable.fromRange(1, 5):with()
  4. expect(observable).to.produce(1, 2, 3, 4, 5)
  5. end)
  6. it('should produce the most recent values when the first observable produces a value', function()
  7. local subjectA = Rx.Subject.create()
  8. local subjectB = Rx.Subject.create()
  9. local onNext = spy()
  10. subjectA:with(subjectB):subscribe(Rx.Observer.create(onNext))
  11. subjectA:onNext('a')
  12. subjectA:onNext('b')
  13. subjectB:onNext('c')
  14. subjectB:onNext('d')
  15. subjectA:onNext('e')
  16. subjectA:onNext('f')
  17. expect(onNext).to.equal({{'a', nil}, {'b', nil}, {'e', 'd'}, {'f', 'd'}})
  18. end)
  19. it('should complete only when the first observable completes', function()
  20. local subjectA = Rx.Subject.create()
  21. local subjectB = Rx.Subject.create()
  22. local onCompleted = spy()
  23. subjectA:with(subjectB):subscribe(Rx.Observer.create(_, _, onCompleted))
  24. subjectA:onNext('a')
  25. subjectB:onNext('b')
  26. subjectB:onCompleted()
  27. expect(#onCompleted).to.equal(0)
  28. subjectA:onNext('c')
  29. subjectA:onNext('d')
  30. subjectA:onCompleted()
  31. expect(#onCompleted).to.equal(1)
  32. end)
  33. end)