36 lines
1.2 KiB
Lua
36 lines
1.2 KiB
Lua
describe('with', function()
|
|
it('returns the observable it is called on if no other sources are specified', function()
|
|
local observable = Rx.Observable.fromRange(1, 5):with()
|
|
expect(observable).to.produce(1, 2, 3, 4, 5)
|
|
end)
|
|
|
|
it('should produce the most recent values when the first observable produces a value', function()
|
|
local subjectA = Rx.Subject.create()
|
|
local subjectB = Rx.Subject.create()
|
|
local onNext = spy()
|
|
subjectA:with(subjectB):subscribe(Rx.Observer.create(onNext))
|
|
subjectA:onNext('a')
|
|
subjectA:onNext('b')
|
|
subjectB:onNext('c')
|
|
subjectB:onNext('d')
|
|
subjectA:onNext('e')
|
|
subjectA:onNext('f')
|
|
expect(onNext).to.equal({{'a', nil}, {'b', nil}, {'e', 'd'}, {'f', 'd'}})
|
|
end)
|
|
|
|
it('should complete only when the first observable completes', function()
|
|
local subjectA = Rx.Subject.create()
|
|
local subjectB = Rx.Subject.create()
|
|
local onCompleted = spy()
|
|
subjectA:with(subjectB):subscribe(Rx.Observer.create(_, _, onCompleted))
|
|
subjectA:onNext('a')
|
|
subjectB:onNext('b')
|
|
subjectB:onCompleted()
|
|
expect(#onCompleted).to.equal(0)
|
|
subjectA:onNext('c')
|
|
subjectA:onNext('d')
|
|
subjectA:onCompleted()
|
|
expect(#onCompleted).to.equal(1)
|
|
end)
|
|
end)
|