mocha command giving ReferenceError: window is not defined

老子叫甜甜 提交于 2019-11-29 01:45:47

问题


I am using command:

mocha --compilers :./test/babel-setup.js --recursive --watch

It is giving error:

ReferenceError: window is not defined

I have the following in my babel-setup.js:

require("babel/register")({
  compact: false
});

I am using node 0.12.7 and "mocha": "^2.2.5" and "jsdom": "^3.1.2".

I already have jsdom installed with the project.

What is causing the error?


回答1:


I was able to use jsdom-global to fix this issue. Follow the instructions in that link to install. Specifically, run

npm install --save-dev --save-exact jsdom jsdom-global

then add -r jsdom-global/register to your mocha command-line. When you re-run your tests, the window is not defined error will go away.




回答2:


To test frontend libraries with mocha you need the node modul mocha-jsdom you find it here: https://www.npmjs.com/package/mocha-jsdom



来源:https://stackoverflow.com/questions/34059644/mocha-command-giving-referenceerror-window-is-not-defined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!