distinctUntilChanged.lua 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. describe('distinctUntilChanged', function()
  2. it('produces an error if its parent errors', function()
  3. expect(Rx.Observable.throw():distinctUntilChanged()).to.produce.error()
  4. end)
  5. describe('with the default comparator', function()
  6. it('produces a value if it is the first value or different from the previous', function()
  7. local observable = Rx.Observable.fromTable({1, 1, 3, 1, 4, 5, 5, 5}, ipairs):distinctUntilChanged()
  8. expect(observable).to.produce(1, 3, 1, 4, 5)
  9. end)
  10. it('produces the first value if it is nil', function()
  11. local observable = Rx.Observable.of(nil):distinctUntilChanged()
  12. expect(observable).to.produce({{}})
  13. end)
  14. it('produces multiple onNext arguments but only uses the first argument to check for equality', function()
  15. local observable = Rx.Observable.fromTable({1, 1, 3, 1, 4, 5, 5, 5}, ipairs, true):distinctUntilChanged()
  16. expect(observable).to.produce({{1, 1}, {3, 3}, {1, 4}, {4, 5}, {5, 6}})
  17. end)
  18. end)
  19. describe('with a custom comparator', function()
  20. it('produces a value if it is the first value or the comparator returns false when passed the previous value and the current value', function()
  21. local observable = Rx.Observable.fromTable({1, 1, 3, 1, 4, 5, 5, 5}, ipairs):distinctUntilChanged(function(x, y) return x % 2 == y % 2 end)
  22. expect(observable).to.produce(1, 4, 5)
  23. end)
  24. it('produces the first value if it is nil', function()
  25. local observable = Rx.Observable.of(nil):distinctUntilChanged(function(x, y) return true end)
  26. expect(observable).to.produce({{}})
  27. end)
  28. it('calls onError if the comparator errors', function()
  29. expect(Rx.Observable.fromRange(2):distinctUntilChanged(error)).to.produce.error()
  30. end)
  31. end)
  32. end)