我如何修复错误类型:无法读取未定义的属性(读取' push)'在React测试中?
通过反应测试图谱进行了测试。我正在实施一个测试,该测试在测试组件的过程中单击按钮时移至主页,但它不起作用。我该如何解决?
我有这个错误 typeError:无法读取未定义的属性(阅读'push')
//Error.test.tsx
test('메인페이지로 이동하는가?', async () => {
const history = createMemoryHistory()
render(
<Router location={history}>
<ErrorCompnent />
</Router>,
)
const user = userEvent.setup()
screen.getByTestId('goHome')
await user.click(screen.getByTestId('goHome'))
// expect(screen.getByTestId('main')).toBeInTheDocument()
})
//Error Component
<button
data-testid="goHome"
onClick={() => {
navigate('/')
}}
>
메인으로 이동
</button>
...
//Main.tsx
<article className={styles.container}>
<section data-testid="main" className={styles.main}>
<div className={styles.column}>
<Calculate />
<PrivateInfo />
</div>
</section>
...
Testing is in progress through react-testing-library. I'm implementing a test that moves to the main page when a button is clicked in the process of testing a component, but it doesn't work. How can I solve this?
i got this error
TypeError: Cannot read properties of undefined (reading 'push')
//Error.test.tsx
test('메인페이지로 이동하는가?', async () => {
const history = createMemoryHistory()
render(
<Router location={history}>
<ErrorCompnent />
</Router>,
)
const user = userEvent.setup()
screen.getByTestId('goHome')
await user.click(screen.getByTestId('goHome'))
// expect(screen.getByTestId('main')).toBeInTheDocument()
})
//Error Component
<button
data-testid="goHome"
onClick={() => {
navigate('/')
}}
>
메인으로 이동
</button>
...
//Main.tsx
<article className={styles.container}>
<section data-testid="main" className={styles.main}>
<div className={styles.column}>
<Calculate />
<PrivateInfo />
</div>
</section>
...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论