test: move beforeunload tests to main runner and fix flake (#18432)

This commit is contained in:
Jeremy Apthorp 2019-05-29 13:38:14 -07:00 committed by GitHub
parent 9af5072115
commit babe2b68fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 67 additions and 53 deletions

View file

@ -9,7 +9,7 @@ const { expect } = chai
chai.use(chaiAsPromised)
const fixturesPath = path.resolve(__dirname, '../spec/fixtures')
const fixturesPath = path.resolve(__dirname, '..', 'spec', 'fixtures')
describe('webContents module', () => {
let w: BrowserWindow = (null as unknown as BrowserWindow)
@ -52,4 +52,25 @@ describe('webContents module', () => {
expect(all[all.length - 1].getType()).to.equal('remote')
})
})
describe('will-prevent-unload event', () => {
it('does not emit if beforeunload returns undefined', (done) => {
w.once('closed', () => done())
w.webContents.once('will-prevent-unload', (e) => {
expect.fail('should not have fired')
})
w.loadFile(path.join(fixturesPath, 'api', 'close-beforeunload-undefined.html'))
})
it('emits if beforeunload returns false', (done) => {
w.webContents.once('will-prevent-unload', () => done())
w.loadFile(path.join(fixturesPath, 'api', 'close-beforeunload-false.html'))
})
it('supports calling preventDefault on will-prevent-unload events', (done) => {
w.webContents.once('will-prevent-unload', event => event.preventDefault())
w.once('closed', () => done())
w.loadFile(path.join(fixturesPath, 'api', 'close-beforeunload-false.html'))
})
})
})