window-helpers.js 555 B

12345678910111213141516171819
  1. const { expect } = require('chai')
  2. const { BrowserWindow } = require('electron').remote
  3. const { emittedOnce } = require('./events-helpers')
  4. exports.closeWindow = async (window = null,
  5. { assertSingleWindow } = { assertSingleWindow: true }) => {
  6. const windowExists = (window !== null) && !window.isDestroyed()
  7. if (windowExists) {
  8. const isClosed = emittedOnce(window, 'closed')
  9. window.setClosable(true)
  10. window.close()
  11. await isClosed
  12. }
  13. if (assertSingleWindow) {
  14. expect(BrowserWindow.getAllWindows()).to.have.lengthOf(1)
  15. }
  16. }