gewl gewl - 1 year ago 96
Javascript Question

Dummying an Electron session for Mocha/Chai tests

I've built a single-page app off of chentsulin's electron/react boilerplate, which comes with the following node script for testing:

"test": "cross-env NODE_ENV=test BABEL_DISABLE_CACHE=1 mocha --compilers js:babel-register --recursive --require ./test/setup.js test/**/*.spec.js"

The boilerplate comes with a number of generic tests that are runnable at the outset (I confirmed this myself). It also comes with a number of webpack configs to suit different environments.

The app is fairly far along now, and is using electron-json-storage to handle local storage. I just went back to writing tests, and when I run the
node script (with or without --renderer) I get the following:

const app = ||;

TypeError: Cannot read property 'app' of undefined

I've tried using webpack.IgnorePlugin to ignore electron-json-storage, but that doesn't do anything. My guess is that electron-json-storage is trying to refer to an instantiated electron session that doesn't exist. What's the easiest way of dummying this up?

Answer Source

The problem was that I was using mocha (which came as part of the Electron-React boilerplate). Installing electron-mocha and changing the test script in the package.json resolved this problem immediately.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download