batcher_spec.js 955 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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('allow diplicate when flushing', function (done) {
  33. batcher.push({
  34. id: 1,
  35. run: function () {
  36. spy()
  37. batcher.push({
  38. id: 1,
  39. run: spy
  40. })
  41. }
  42. })
  43. nextTick(function () {
  44. expect(spy.calls.count()).toBe(2)
  45. done()
  46. })
  47. })
  48. })