2

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?

Roman
  • 19,236
  • 15
  • 93
  • 97

1 Answers1

3

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",
    },
    
Roman
  • 19,236
  • 15
  • 93
  • 97