给出ReferenceError:窗口未定义的mocha命令 [英] mocha command giving ReferenceError: window is not defined

查看:74
本文介绍了给出ReferenceError:窗口未定义的mocha命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用命令:

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

出现错误:

ReferenceError: window is not defined

我的babel-setup.js文件中包含以下内容:

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

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

我正在使用节点0.12.7和"mocha":"^ 2.2.5"和"jsdom":"^ 3.1.2".

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

我已经在项目中安装了 jsdom .

I already have jsdom installed with the project.

是什么原因导致错误?

推荐答案

我能够使用 jsdom-global 解决此问题.按照该链接中的说明进行安装.具体来说,运行

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

然后将-r jsdom-global/register添加到您的Mocha命令行中.当您重新运行测试时,window is not defined错误将消失.

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.

这篇关于给出ReferenceError:窗口未定义的mocha命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆