filter.lua 984 B

1234567891011121314151617181920212223242526
  1. describe('filter', function()
  2. it('uses the identity function as the predicate if none is specified', function()
  3. local observable = Rx.Observable.fromTable({false, true}):filter()
  4. expect(observable).to.produce(true)
  5. end)
  6. it('passes all arguments to the predicate', function()
  7. local predicate = spy()
  8. Rx.Observable.fromTable({{1, 2}, {3, 4, 5}}, ipairs):unpack():filter(predicate):subscribe()
  9. expect(predicate).to.equal({{1, 2}, {3, 4, 5}})
  10. end)
  11. it('does not produce elements that the predicate returns false for', function()
  12. local predicate = function(x) return x % 2 == 0 end
  13. local observable = Rx.Observable.fromRange(1, 5):filter(predicate)
  14. expect(observable).to.produce(2, 4)
  15. end)
  16. it('errors when its parent errors', function()
  17. expect(Rx.Observable.throw():filter()).to.produce.error()
  18. end)
  19. it('calls onError if the predicate errors', function()
  20. expect(Rx.Observable.of(5):filter(error)).to.produce.error()
  21. end)
  22. end)