//定时器函数代码//
Function startTimer (event) { var session Timeout= setTimeout (function () { Self.postMessage ( { Message:'show dialog' }; ); }, event.duration); }
Function startTimer (event)
{
var session Timeout=
setTimeout (function ()
Self.postMessage (
Message:'show dialog'
};
);
}, event.duration);
}
如何编写测试用例?
vlju58qv1#
参考Jest中提供的计时器模拟https://jestjs.io/docs/timer-mocks
jest.useFakeTimers();jest.spyOn(global, 'setTimeout');test('Timer Function', () => { const startTimer = require('../startTimer '); startTimer (); expect(setTimeout).toHaveBeenCalledTimes(1); expect(setTimeout).toHaveBeenLastCalledWith(expect.any(Function), event.duration);});
jest.useFakeTimers();
jest.spyOn(global, 'setTimeout');
test('Timer Function', () => {
const startTimer = require('../startTimer ');
startTimer ();
expect(setTimeout).toHaveBeenCalledTimes(1);
expect(setTimeout).toHaveBeenLastCalledWith(expect.any(Function), event.duration);
});
1条答案
按热度按时间vlju58qv1#
参考Jest中提供的计时器模拟
https://jestjs.io/docs/timer-mocks