我正在使用 Spectron 测试一个简单的电子应用程序。以下是我的 test.js 有一个测试用例来单击一个元素。
const Application = require('spectron').Application;
const assert = require('assert');
const electronPath = require('electron'); // Require Electron from the binaries included in node_modules.
const path = require('path');
describe('Application launch', function () {
this.timeout(30000);
beforeEach(function () {
this.app = new Application({
path: electronPath,
args: [path.join(__dirname, '..')]
});
return this.app.start();
});
afterEach(function () {
if (this.app && this.app.isRunning()) {
return this.app.stop();
}
});
it('shows an initial window', function () {
return this.app.client.getWindowCount().then(function (count) {
assert.equal(count, 1);
});
});
it('Navigate to settings', async function () {
return this.app.client.click('#settings').then(function (data) {
console.log(data);
});
});
});
当我运行 mocha 以下是输出。
√ shows an initial window
1) Navigate to settings
1 passing (45s)
1 failing
1) Application launch
Navigate to settings:
TypeError: this.app.client.click is not a function
at Context.<anonymous> (test\test.js:30:28)
at process._tickCallback (internal/process/next_tick.js:68:7)
npm ERR! Test failed. See above for more details.
我是摩卡测试的新手,我无法找到解决方案。提前致谢。