test timers in react, sinon or jest
test timers in react, sinon or jest I have a funtion checkIdleTime , being set to be called periodically. checkIdleTime componentDidMount() { var idleCheck = setInterval(this.checkIdleTime.bind(this), authTimeoutSeconds * 1000); this.setState({idleCheck: idleCheck}); document.onkeypress = this.setActive; } I want to use the fake timer for test, but can't figure out how, tried sinon and jest . sinon jest beforeEach(() => { checkIdleTime = jest.spyOn(PureMain.prototype, 'checkIdleTime'); wrapper = shallow( <PureMain/> ); jest.useFakeTimers(); //clock = sinon.useFakeTimers(); }); it('should check the idle time after [authTimeoutSeconds] seconds of inactivity', () => { wrapper.instance().componentDidMount(); var idleCheck_timeout = wrapper.instance().state.idleCheck; expect(idleCheck_timeout).not.toEqual(null); expect(idleCheck_timeout._idleTimeout).toBe(authTimeoutSeconds * 1000); jest.runAllTi...