Describe the bug
The documented mocha testing examples have two problems.
To Reproduce
Steps to reproduce the behavior:
Clone https://github.com/itsMikeLowrey/testtingSpectron and run yarn run test:mocha
Expected behavior
I expected the mocha testing to function correctly.
Environment (please complete the following information):
vue info:System:
OS: Windows 10 10.0.19041
CPU: (4) x64 Intel(R) Core(TM) i5-4330M CPU @ 2.80GHz
Binaries:
Node: 12.18.3 - ~\AppData\Local\Tempyarn--1597901458404-0.7356708428238694\node.CMD
Yarn: 1.22.4 - ~\AppData\Local\Tempyarn--1597901458404-0.7356708428238694yarn.CMD
npm: 6.14.6 - C:\Program Files\nodejs\npm.CMD
Browsers:
Chrome: 84.0.4147.135
Edge: Spartan (44.19041.1.0)
npmPackages:
@ant-design-vue/babel-helper-vue-transform-on: 1.0.1
@vue/babel-helper-vue-jsx-merge-props: 1.0.0
@vue/babel-plugin-transform-vue-jsx: 1.1.2
@vue/babel-preset-app: 4.5.4
@vue/babel-preset-jsx: 1.1.2
@vue/babel-sugar-functional-vue: 1.1.2
@vue/babel-sugar-inject-h: 1.1.2
@vue/babel-sugar-v-model: 1.1.2
@vue/babel-sugar-v-on: 1.1.2
@vue/cli: ^4.5.4 => 4.5.4
@vue/cli-overlay: 4.5.4
@vue/cli-plugin-babel: ~4.5.0 => 4.5.4
@vue/cli-plugin-eslint: ~4.5.0 => 4.5.4
@vue/cli-plugin-router: 4.5.4
@vue/cli-plugin-vuex: 4.5.4
@vue/cli-service: ~4.5.0 => 4.5.4
@vue/cli-shared-utils: 4.5.4
@vue/cli-ui: 4.5.4
@vue/cli-ui-addon-webpack: 4.5.4
@vue/cli-ui-addon-widgets: 4.5.4
@vue/compiler-core: 3.0.0-rc.6
@vue/compiler-dom: 3.0.0-rc.6
@vue/compiler-sfc: undefined (3.0.0-rc.6)
@vue/compiler-ssr: 3.0.0-rc.6
@vue/component-compiler-utils: 3.2.0
@vue/preload-webpack-plugin: 1.1.2
@vue/reactivity: 3.0.0-rc.6
@vue/runtime-core: 3.0.0-rc.6
@vue/runtime-dom: 3.0.0-rc.6
@vue/shared: 3.0.0-rc.6
@vue/web-component-wrapper: 1.2.0
eslint-plugin-vue: ^6.2.2 => 6.2.2
typescript: 3.9.7
vue: ^2.6.11 => 2.6.11 (3.0.0-rc.6)
vue-cli-plugin-apollo: 0.21.3
vue-cli-plugin-electron-builder: ~2.0.0-rc.4 => 2.0.0-rc.4
vue-codemod: 0.0.4
vue-eslint-parser: 7.1.0
vue-hot-reload-api: 2.3.4
vue-loader: 15.9.3 (16.0.0-beta.5)
vue-style-loader: 4.1.2
vue-template-compiler: ^2.6.11 => 2.6.11
vue-template-es2015-compiler: 1.9.1
npmGlobalPackages:
@vue/cli: Not Found
Additional context
The first issue that comes up is Error: Invalid Chai property: browserWindow.
This can be temporarily fixed by removing the problem code @ line 33 of test.spec.js.
The second issue is that the test always pass regardless if it should and it throws an assertion error. For example if I change the code at line 30 to
return this.app.client
.getWindowCount()
.should.eventually.have.at.least(45)
the test still passes but it returns this error:
UnhandledPromiseRejectionWarning: AssertionError: expected 1 to be at least 45
Flip lines 6 and 7, chai.should() needs to come after chai.use(chaiAsPromised). After that, the tests fail on the incorrect assertion and pass if you change 99 to 1.
My bad, I realized I switched to a different project halfway through debugging :facepalm:.
Okay the real issue is caused by spectron, version 11.1.0 has some breaking changes from 11.0.0 that mess some things up. See https://github.com/electron-userland/spectron/issues/647 for more details.
To fix, just use "spectron": "11.0.0", in your package.json.
Also, instead of using your own mocha config, try the official cli plugin, it may make things easier.