Przeglądaj źródła

Test Observable.with;

bjorn 10 lat temu
rodzic
commit
8c9e1fc241
2 zmienionych plików z 36 dodań i 0 usunięć
  1. 1 0
      tests/observable.lua
  2. 35 0
      tests/with.lua

+ 1 - 0
tests/observable.lua

@@ -177,5 +177,6 @@ describe('Observable', function()
   dofile('tests/unpack.lua')
   dofile('tests/unwrap.lua')
   dofile('tests/window.lua')
+  dofile('tests/with.lua')
   dofile('tests/wrap.lua')
 end)

+ 35 - 0
tests/with.lua

@@ -0,0 +1,35 @@
+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 onComplete = spy()
+    subjectA:with(subjectB):subscribe(Rx.Observer.create(_, _, onComplete))
+    subjectA:onNext('a')
+    subjectB:onNext('b')
+    subjectB:onComplete()
+    expect(#onComplete).to.equal(0)
+    subjectA:onNext('c')
+    subjectA:onNext('d')
+    subjectA:onComplete()
+    expect(#onComplete).to.equal(1)
+  end)
+end)