[英]how to write test case for nested jsx returning function using jest and react testing library
[英]How to write a test case for this function in jest
// 定時器函數代碼//
Function startTimer (event)
{
var session Timeout=
setTimeout (function ()
{
Self.postMessage (
{
Message:'show dialog'
};
);
}, event.duration);
}
如何為此編寫測試用例?
參考 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);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.