提问人:Nhan Nguyen 提问时间:11/17/2023 最后编辑:Drew ReeseNhan Nguyen 更新时间:11/17/2023 访问量:20
使用 react jest 和 selenium 对 onclick 导航进行单元测试
Unit testing for onclick navigation using react jest and selenium
问:
我正在尝试差异测试用例,但我编写的测试用例仍然没有涵盖 onClick 代码
这是我的手柄按钮功能:
const handleBackButtonClick = () => {
dispatch(setErrorCode(''));
buttonClickEvent(
userDetails.sid,
'Product Inventory',
'Go bacl Button',
window
);
navigate(-1);
}
<Button
accessibleText="Go to previous page"
data-testid="goBackNavBar"
id="back-page"
variant="back"
maxWidth={5000}
pageName={pageName}
backButtonText="Back"
backButtonAccessibleText="Go to previous page"
onClickBackButton={handleBackButtonClick}
/>
这是我写的测试用例:
describe('Layout Component', () => {
it('navigates back when back button is clicked', () => {
renderWithProviders(<Layout>children</Layout>, { store });
const onClick = screen.getByTestId('goBackNavBar');
const handleBackButton = jest.fn();
fireEvent(
screen.getByTestId('goBackNavBar'),
new Event('click', {})
);
fireEvent.click(onClick);
expect(handleBackButton).toBeDefined();
});
});
我想编写一个涵盖我的句柄函数的测试
答: 暂无答案
评论
handleBackButtonClick
handleBackButtonClick
Button
Layout