我是 NextJS 环境的初学者,我正在从常见的 ReactJS 迁移应用程序。这是对另一个页面链接的简单测试。那么,我应该如何重构我的测试?
*我正在使用 Jest 和测试库。
// My current code in ReactJS
test('Should go to Post page', () => {
const post = mockPostModel()
const history = createMemoryHistory({ initialEntries: ['/'] })
render(
<Router history={history}>
<BlogPost post={post} />
</Router>
)
fireEvent.click(screen.getByTestId('link'))
expect(history.location.pathname).toBe(`/post/${post.title}`)
})
Run Code Online (Sandbox Code Playgroud)