Browse Source

Test Observable.map;

bjorn 10 years ago
parent
commit
00d523cca5
2 changed files with 20 additions and 0 deletions
  1. 19 0
      tests/map.lua
  2. 1 0
      tests/observable.lua

+ 19 - 0
tests/map.lua

@@ -0,0 +1,19 @@
+describe('map', 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:map().subscribe).to.fail()
+  end)
+
+  it('uses the identity function as the callback if none is specified', function()
+    local observable = Rx.Observable.fromRange(5):map()
+    expect(observable).to.produce(1, 2, 3, 4, 5)
+  end)
+
+  it('passes all arguments to the predicate and produces all of its return values', function()
+    local callback = spy(function() return 1, 2, 3 end)
+    local observable = Rx.Observable.fromTable({3, 2, 1}, ipairs, true):map(callback)
+    expect(observable).to.produce({{1, 2, 3}, {1, 2, 3}, {1, 2, 3}})
+    expect(callback).to.equal({{3, 1}, {2, 2}, {1, 3}})
+  end)
+end)

+ 1 - 0
tests/observable.lua

@@ -160,4 +160,5 @@ describe('Observable', function()
   dofile('tests/first.lua')
   dofile('tests/flatten.lua')
   dofile('tests/last.lua')
+  dofile('tests/map.lua')
 end)