Skip to content
New issue

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

jest 踩坑记录 #64

Open
chenxiaochun opened this issue Nov 30, 2018 · 0 comments
Open

jest 踩坑记录 #64

chenxiaochun opened this issue Nov 30, 2018 · 0 comments

Comments

@chenxiaochun
Copy link
Owner

chenxiaochun commented Nov 30, 2018

错误异常一

当运行单元测试时,如果抛出了下面的异常。说明你的代码中使用了window.location.href,而在 jsdom 环境中并没有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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant