123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- import Interval from 'handsontable/utils/interval';
- describe('Interval', () => {
- it('should create instance of Interval object', () => {
- var i = Interval.create(() => {}, 10);
- expect(i instanceof Interval).toBe(true);
- });
- it('should create object with delay passed as number', () => {
- var i = Interval.create(() => {}, 15);
- expect(i.delay).toBe(15);
- });
- it('should create object with delay passed as a number of FPS', () => {
- var i = Interval.create(() => {}, '60fps');
- expect(i.delay).toBe(1000 / 60);
- });
- it('should create interval object which is stopped by default', (done) => {
- var spy = jasmine.createSpy();
- var i = Interval.create(spy);
- setTimeout(() => {
- expect(spy).not.toHaveBeenCalled();
- done();
- }, 100);
- });
- it('should repeatedly invoke callback function after calling `start` method', (done) => {
- var spy = jasmine.createSpy();
- var i = Interval.create(spy, 100);
- i.start();
- setTimeout(() => {
- expect(spy).not.toHaveBeenCalled();
- }, 50);
- setTimeout(() => {
- expect(spy.calls.count()).toBe(1);
- }, 150);
- setTimeout(() => {
- expect(spy.calls.count()).toBe(2);
- }, 250);
- setTimeout(() => {
- expect(spy.calls.count()).toBe(3);
- i.stop();
- done();
- }, 350);
- });
- it('should stop repeatedly invoking callback function after calling `stop` method', (done) => {
- var spy = jasmine.createSpy();
- var i = Interval.create(spy, 100);
- i.start();
- setTimeout(() => {
- expect(spy).not.toHaveBeenCalled();
- }, 50);
- setTimeout(() => {
- expect(spy.calls.count()).toBe(1);
- i.stop();
- }, 150);
- setTimeout(() => {
- expect(spy.calls.count()).toBe(1);
- i.start();
- }, 250);
- setTimeout(() => {
- expect(spy.calls.count()).toBe(2);
- i.stop();
- done();
- }, 400);
- });
- });
|