electron-vue makes use of Spectron and the Mocha (with Chai) test framework for end-to-end testing. Mocha & Chai APIs, including expect
, should
, and assert
, are made available in global scope.
# Begins Mocha
npm run e2e
Before running end-to-end tests, a npm run pack
is called to create a production build that Spectron can consume during tests.
my-project
├─ test
| ├─ e2e
│ │ ├─ specs/
│ │ ├─ index.js
└─ └─ └─ utils.js
For the most part, you can ignore index.js
and focus solely on writing specs/
.
Inside this directory is where actual tests are written. Thanks to the power of babel-register
, you have full access to ES2015.
This file acts as the main entry to Mocha and gathers all tests written in specs/
for testing.
Here you will find generic functions that could be of use throughout your specs/
. Base functions include a beforeEach
and afterEach
that handle the electron process.
Spectron is the official electron testing framework that uses both ChromeDriver and WebDriverIO for manipulating DOM elements.
As stated in the Spectron documentation, access to WebDriverIO APIs can be accessed through this.app.client
. Because electron-vue uses Mocha, the context of this
is shared between afterEach
, beforeEach
, and it
. Because of this, it is important to note that ES2015 arrow functions cannot not be used in certain situations as the context of this
will be overwritten (more info).