testing setInterval - hogehoge666/syno_moments_slider GitHub Wiki

use done() to finish the timer

    it('should execute callback, set timerId, and set isMoving to true when started', (done) => {
        let count = 0;
        const timer = new PhotoTimer(() => {
            console.log('callback executed');
            done();
        }, 0.5);
        timer.start();
        expect(timer.isMoving).toBeTruthy();
        expect(timer._timerId).not.toBe(0);
    });

https://jestjs.io/docs/en/asynchronous