浏览代码

Test Observable.window;

bjorn 10 年之前
父节点
当前提交
9e3996a97f
共有 2 个文件被更改,包括 17 次插入0 次删除
  1. 1 0
      tests/observable.lua
  2. 16 0
      tests/window.lua

+ 1 - 0
tests/observable.lua

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

+ 16 - 0
tests/window.lua

@@ -0,0 +1,16 @@
+describe('window', function()
+  it('produces an error if its parent errors', function()
+    local observable = Rx.Observable.fromValue(''):map(function(x) return x() end)
+    expect(observable.subscribe).to.fail()
+    expect(observable:window().subscribe).to.fail()
+  end)
+
+  it('fails if size is not specified', function()
+    expect(Rx.Observable.fromRange(5):window().subscribe).to.fail()
+  end)
+
+  it('produces a specified number of the most recent values', function()
+    expect(Rx.Observable.fromRange(3):window(2)).to.produce({{1, 2}, {2, 3}})
+    expect(Rx.Observable.fromRange(3):window(3)).to.produce({{1, 2, 3}})
+  end)
+end)