count.lua 794 B

12345678910111213141516171819202122
  1. describe('count', function()
  2. it('passes through errors', function()
  3. local _, onError = observableSpy(Rx.Observable.throw():count())
  4. expect(#onError).to.equal(1)
  5. end)
  6. it('produces a single value representing the number of elements produced by the source', function()
  7. local observable = Rx.Observable.fromRange(5):count()
  8. expect(observable).to.produce(5)
  9. end)
  10. it('uses the predicate to filter for values if it is specified', function()
  11. local observable = Rx.Observable.fromRange(5):count(function(x) return x > 3 end)
  12. expect(observable).to.produce(2)
  13. end)
  14. it('calls onError if the predicate errors', function()
  15. local onError = spy()
  16. Rx.Observable.fromRange(3):count(error):subscribe(nil, onError, nil)
  17. expect(#onError).to.equal(1)
  18. end)
  19. end)