繁体   English   中英

使用 jest 运行测试时 URLSearchParams 未定义错误

[英]URLSearchParams is not defined error when running tests with jest

使用 Jest 运行测试时如何使用 URLSearchParams ?

当我这样做时,我得到

ReferenceError: URLSearchParams is not defined

你只需要升级你的react-scripts版本,它使用包含使用 URLSearchParams 功能的最新版本的 Jest。

您可以在这里阅读更多相关信息: https ://facebook.github.io/jest/blog/2017/12/18/jest-22.html#good-bye-node-4-welcome-jsdom-11。

您是否将您的 jest 环境设置为配置文件中的默认值以外的其他内容? 您必须运行将 jest 环境设置为jsdom ,以便可以使用常见的浏览器特定 JavaScript 组件

jest --env=jsdom

请参阅配置 Jest

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM