Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mocha command giving ReferenceError: window is not defined

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?

like image 672
jit Avatar asked Dec 03 '15 06:12

jit


1 Answers

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.

like image 70
emmby Avatar answered Sep 20 '22 11:09

emmby