mocha-webpack ReferenceError: window is not defined

1.7k Views Asked by At

I use NodeJS and mocha-webpack as a testing tool. Then I get an error in the terminal:

ReferenceError: window is not defined
...

I have in package.json:

"scripts": {
    "tws": "mocha-webpack -r ./test/test*.js",  
    "tw": "mocha-webpack --watch ./test/test*.js",
},

What is an issue and solution?

1

There are 1 best solutions below

0
On

I find a solution. It is necessary

  1. to install jsdom-global:

    npm install jsdom-global
    
  2. to change the package.json like this:

    "scripts": {
        "tws": "mocha-webpack -r jsdom-global/register ./test/test*.js",    
        "tw": "mocha-webpack --watch -r jsdom-global/register ./test/test*.js",
    },