我正在使用命令:
mocha --compilers :./test/babel-setup.js --recursive --watch
报错:
ReferenceError: window is not defined
我的 babel-setup.js 中有以下内容:
require("babel/register")({
compact: false
});
我正在使用 Node 0.12.7 和“mocha”:“^2.2.5”和“jsdom”:“^3.1.2”。
我已经在项目中安装了 jsdom。
是什么导致了错误?
最佳答案
我可以使用 jsdom-global
来解决这个问题。按照该链接中的说明进行安装。具体来说,运行
npm install --save-dev --save-exact jsdom jsdom-global
然后将 -r jsdom-global/register
添加到你的 mocha 命令行。当您重新运行测试时,window is not defined
错误将消失。
关于node.js - mocha 命令给出 ReferenceError : window is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34059644/