TimerMock
가짜 타이머 활성화
function timerGame(callback) {
console.log("Ready....go!");
setTimeout(() => {
console.log("Time's up -- stop!");
callback && callback();
}, 1000);
}
module.exports = timerGame;jest.useFakeTimers();
jest.spyOn(global, "setTimeout");
test("게임이 끝나기 전에 1초를 기다립니다.", () => {
const timerGame = require("../timerGame");
timerGame();
expect(setTimeout).toHaveBeenCalledTimes(1);
expect(setTimeout).toHaveBeenLastCalledWith(expect.any(Function), 1000);
});모든 타이머 실행
대기 중인 타이머 실행
타이머를 시간 단위로 진행
Last updated