all.lua 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. describe('all', function()
  2. it('passes through errors', function()
  3. expect(Rx.Observable.throw():all().subscribe).to.fail()
  4. end)
  5. it('calls onError if the predicate errors', function()
  6. local observable = Rx.Observable.fromRange(3):all(error)
  7. local onError = spy()
  8. observable:subscribe(nil, onError, nil)
  9. expect(#onError).to.equal(1)
  10. end)
  11. it('produces an error if the parent errors', function()
  12. local _, onError = observableSpy(Rx.Observable.throw():all(function(x) return x end))
  13. expect(#onError).to.equal(1)
  14. end)
  15. it('produces true if all elements satisfy the predicate', function()
  16. local observable = Rx.Observable.fromRange(5):all(function(x) return x < 10 end)
  17. expect(observable).to.produce({{true}})
  18. end)
  19. it('produces false if one element does not satisfy the predicate', function()
  20. local observable = Rx.Observable.fromRange(5):all(function(x) return x ~= 3 end)
  21. expect(observable).to.produce({{false}})
  22. end)
  23. it('uses the identity function as a predicate if none is specified', function()
  24. local observable = Rx.Observable.of(false):all()
  25. expect(observable).to.produce({{false}})
  26. observable = Rx.Observable.of(true):all()
  27. expect(observable).to.produce({{true}})
  28. end)
  29. end)