【发布时间】:2019-11-21 06:04:49
【问题描述】:
我有一个多窗口电子应用程序,即它由一个启动器窗口和一个主窗口组成。
主进程负责首先显示启动器,一切初始化后,它通过 ipc 获取事件并显示主窗口,隐藏启动器。
我在主窗口上使用on('close') 来检测用户何时关闭主窗口,再次显示启动器并执行一些拆卸逻辑,完成后应用程序退出。
this.mainWindow = new BrowserWindow({width: 1024, height: 768, webPreferences: {nodeIntegration: true}});
this.mainWindow.setMenu(null);
this.mainWindow.on('close', () => {
this.logger.debug('"close" received');
this.mainWindow.hide();
this.launcherWindow.show();
this.sendShutdown();
});
这很好用,现在我想用 Spectron 集成测试这种行为。我在向窗口发送关闭信号时遇到问题,模拟用户点击关闭。
it('should start shutting down the services gracefully if the user clicks on the close button', async () => {
await app.client.windowByIndex(1);
await app.client.close();
//..... expectations that verify the launcher window is visible now
});
我已验证索引为 1 的窗口是主窗口。当我调用app.client.close(); 时,主窗口关闭,但我可以在日志中看到主窗口的on('close', ) 事件没有被触发,因此它不会跳回启动器。
我有什么遗漏/误解吗?
【问题讨论】:
标签: typescript electron integration-testing spectron