mfr*_*het 2 javascript electron spectron
我正在尝试使用Electron构建应用程序.
我需要根据电子env和使用电子封装进行一些单元测试.
这样,我使用spectron来模拟我的应用程序.
在文档中,我写道我必须在'path'属性中放入我的可执行文件所在的路径.我现在没有可执行文件,我处于开发模式.
以下是我根据另一个问题尝试的内容:
beforeEach(() => {
app = new Application({
path: 'node_modules/.bin/electron'
});
app.start().then(res => console.log(res), err => console.log(err));
});
Run Code Online (Sandbox Code Playgroud)
提示中没有任何内容,并且以下测试失败告诉我无法在未定义的对象上获取getWindowCount(显然,应用程序未实例化):
it('should call currentWindow', (done) => {
app.client.getWindowCount().then((count) => {
expect(count).to.equals(1);
done();
});
});
Run Code Online (Sandbox Code Playgroud)
有谁知道我应该在这条道路上放置什么来让我的测试环境工作?
PS:我使用摩卡柴和sinon.
谢谢你的帮助
起初我是为了测试而创建一个可执行文件,但实际上并不是必需的.
该示例传递了一个名为args的选项,这正是您所缺少的.这就是我在做的事情:
var appPath = path.resolve(__dirname, '../'); //require the whole thing
var electronPath = path.resolve(__dirname, '../node_modules/.bin/electron');
beforeEach(function() {
myApp = new Application({
path: electronPath,
args: [appPath], // pass args along with path
});
return myApp.start().then(function() {
assert.equal(myApp.isRunning(), true);
chaiAsPromised.transferPromiseness = myApp.transferPromiseness;
return myApp;
});
});
Run Code Online (Sandbox Code Playgroud)
我的测试位于./tests/app-test.js.以上对我有用.