尝试使用笑话酶测试React JS。当我尝试测试点击事件之一时,出现以下错误:
SecurityError
at HistoryImpl._sharedPushAndReplaceState (node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/living/window/History-impl.js:97:15)
at node_modules/history/createBrowserHistory.js:175:23
at Object.confirmTransitionTo (node_modules/history/createTransitionManager.js:44:7)
at Object.push (node_modules/history/createBrowserHistory.js:166:23)
我已经在线尝试了一些答案,例如:
{ //这将使用URL配置jsdom文档。 testURL:“ http://localhost”, }
还尝试了以下内容:
import jsdom from 'jsdom';
const {JSDOM} = jsdom;
const {document} = (new JSDOM('<!doctype html><html><body></body></html>')).window;
global.document = document;
global.window = document.defaultView;
但是我仍然遇到相同的错误。