【发布时间】:2021-12-13 08:38:34
【问题描述】:
如何为以下函数编写测试用例? 预期是:如果提供了 successPath,则 onSignInSuccess 应将其重定向到 successPath
export const onSignInSuccess = ( data ) => {
return ( ) => {
global.location.href = data?.detail?.data?.successPath;
}
}
到目前为止我尝试过但它不起作用
const data = { detail : { data: { redirectPage: true, successPath: 'test.com' } } }
onSignInSuccess( data )()
expect( jest.fn() ).toHaveBeenCalledWith( 'test.com' )
【问题讨论】:
-
expect( jest.fn() ).toHaveBeenCalledWith( 'test.com' )- 期待我刚刚创建的这个模拟函数以某种方式已经被调用?无论如何,被测代码都没有调用任何东西,这个断言没有任何意义。 -
对不起@jonrsharpe 我没有得到你,但我更新了问题。
标签: javascript function jestjs