2
0

batcher_spec.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. var Batcher = require('../../../src/batcher')
  2. var nextTick = require('../../../src/util').nextTick
  3. describe('Batcher', function () {
  4. var batcher = new Batcher()
  5. var spy
  6. beforeEach(function () {
  7. spy = jasmine.createSpy('batcher')
  8. })
  9. it('push', function (done) {
  10. batcher.push({
  11. run: spy
  12. })
  13. nextTick(function () {
  14. expect(spy.calls.count()).toBe(1)
  15. done()
  16. })
  17. })
  18. it('dedup', function (done) {
  19. batcher.push({
  20. id: 1,
  21. run: spy
  22. })
  23. batcher.push({
  24. id: 1,
  25. run: spy
  26. })
  27. nextTick(function () {
  28. expect(spy.calls.count()).toBe(1)
  29. done()
  30. })
  31. })
  32. it('override', function (done) {
  33. var spy2 = jasmine.createSpy('batcher')
  34. batcher.push({
  35. id: 1,
  36. run: spy
  37. })
  38. batcher.push({
  39. id: 1,
  40. run: spy2,
  41. override: true
  42. })
  43. nextTick(function () {
  44. expect(spy.calls.count()).toBe(0)
  45. expect(spy2.calls.count()).toBe(1)
  46. done()
  47. })
  48. })
  49. it('preFlush hook', function (done) {
  50. batcher._preFlush = spy
  51. batcher.push({ run: function () {}})
  52. nextTick(function () {
  53. expect(spy.calls.count()).toBe(1)
  54. done()
  55. })
  56. })
  57. })