Interval.spec.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import Interval from 'handsontable/utils/interval';
  2. describe('Interval', () => {
  3. it('should create instance of Interval object', () => {
  4. var i = Interval.create(() => {}, 10);
  5. expect(i instanceof Interval).toBe(true);
  6. });
  7. it('should create object with delay passed as number', () => {
  8. var i = Interval.create(() => {}, 15);
  9. expect(i.delay).toBe(15);
  10. });
  11. it('should create object with delay passed as a number of FPS', () => {
  12. var i = Interval.create(() => {}, '60fps');
  13. expect(i.delay).toBe(1000 / 60);
  14. });
  15. it('should create interval object which is stopped by default', (done) => {
  16. var spy = jasmine.createSpy();
  17. var i = Interval.create(spy);
  18. setTimeout(() => {
  19. expect(spy).not.toHaveBeenCalled();
  20. done();
  21. }, 100);
  22. });
  23. it('should repeatedly invoke callback function after calling `start` method', (done) => {
  24. var spy = jasmine.createSpy();
  25. var i = Interval.create(spy, 100);
  26. i.start();
  27. setTimeout(() => {
  28. expect(spy).not.toHaveBeenCalled();
  29. }, 50);
  30. setTimeout(() => {
  31. expect(spy.calls.count()).toBe(1);
  32. }, 150);
  33. setTimeout(() => {
  34. expect(spy.calls.count()).toBe(2);
  35. }, 250);
  36. setTimeout(() => {
  37. expect(spy.calls.count()).toBe(3);
  38. i.stop();
  39. done();
  40. }, 350);
  41. });
  42. it('should stop repeatedly invoking callback function after calling `stop` method', (done) => {
  43. var spy = jasmine.createSpy();
  44. var i = Interval.create(spy, 100);
  45. i.start();
  46. setTimeout(() => {
  47. expect(spy).not.toHaveBeenCalled();
  48. }, 50);
  49. setTimeout(() => {
  50. expect(spy.calls.count()).toBe(1);
  51. i.stop();
  52. }, 150);
  53. setTimeout(() => {
  54. expect(spy.calls.count()).toBe(1);
  55. i.start();
  56. }, 250);
  57. setTimeout(() => {
  58. expect(spy.calls.count()).toBe(2);
  59. i.stop();
  60. done();
  61. }, 400);
  62. });
  63. });