We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
当运行单元测试时,如果抛出了下面的异常。说明你的代码中使用了window.location.href,而在 jsdom 环境中并没有location这个对象,所以就抛出了异常。
window.location.href
location
Error: Not implemented: navigation (except hash changes)
解决办法就是将你源代码中的window.location.href替换成window.location.assign(url)。然后在单元测试中使用jest.spyOn(window.location, 'assign').mockImplementation(() => jest.fn())来 mock 这个方法即可解决问题。具体详情可参考 #2112。
window.location.assign(url)
jest.spyOn(window.location, 'assign').mockImplementation(() => jest.fn())
The text was updated successfully, but these errors were encountered:
No branches or pull requests
错误异常一
当运行单元测试时,如果抛出了下面的异常。说明你的代码中使用了
window.location.href
,而在 jsdom 环境中并没有location
这个对象,所以就抛出了异常。解决办法就是将你源代码中的
window.location.href
替换成window.location.assign(url)
。然后在单元测试中使用jest.spyOn(window.location, 'assign').mockImplementation(() => jest.fn())
来 mock 这个方法即可解决问题。具体详情可参考 #2112。The text was updated successfully, but these errors were encountered: