count.lua 677 B

1234567891011121314151617
  1. describe('count', function()
  2. it('passes through errors', function()
  3. local observable = Rx.Observable.create(function(observer) observer:onError() end)
  4. expect(observable.subscribe).to.fail()
  5. expect(observable:count().subscribe).to.fail()
  6. end)
  7. it('produces a single value representing the number of elements produced by the source', function()
  8. local observable = Rx.Observable.fromRange(5):count()
  9. expect(observable).to.produce(5)
  10. end)
  11. it('uses the predicate to filter for values if it is specified', function()
  12. local observable = Rx.Observable.fromRange(5):count(function(x) return x > 3 end)
  13. expect(observable).to.produce(2)
  14. end)
  15. end)