spec: refactor helper closeWindow() function (#13337)

This commit is contained in:
Alexey Kuzmin 2018-06-21 16:43:15 +02:00 committed by Samuel Attard
parent b9da1575f0
commit 10a174fc6a

View file

@ -1,22 +1,19 @@
const assert = require('assert') const {expect} = require('chai')
const {BrowserWindow} = require('electron').remote const {BrowserWindow} = require('electron').remote
exports.closeWindow = (window, {assertSingleWindow} = {assertSingleWindow: true}) => { const {emittedOnce} = require('./events-helpers')
if (window == null || window.isDestroyed()) {
if (assertSingleWindow) { exports.closeWindow = async (window = null,
assert.equal(BrowserWindow.getAllWindows().length, 1) {assertSingleWindow} = {assertSingleWindow: true}) => {
} const windowExists = (window !== null) && !window.isDestroyed()
return Promise.resolve() if (windowExists) {
} else { const isClosed = emittedOnce(window, 'closed')
return new Promise((resolve, reject) => { window.setClosable(true)
window.once('closed', () => { window.close()
if (assertSingleWindow) { await isClosed
assert.equal(BrowserWindow.getAllWindows().length, 1) }
}
resolve() if (assertSingleWindow) {
}) expect(BrowserWindow.getAllWindows()).to.have.lengthOf(1)
window.setClosable(true)
window.close()
})
} }
} }