refactor: use types for once() return values in spec (#38872)

This commit is contained in:
Milan Burda 2023-06-22 20:38:52 +02:00 committed by GitHub
parent abec9ead06
commit 9226cc662b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 85 additions and 85 deletions

View file

@ -6,7 +6,7 @@ import * as net from 'node:net';
import * as fs from 'fs-extra';
import * as path from 'node:path';
import { promisify } from 'node:util';
import { app, BrowserWindow, Menu, session, net as electronNet } from 'electron/main';
import { app, BrowserWindow, Menu, session, net as electronNet, WebContents } from 'electron/main';
import { closeWindow, closeAllWindows } from './lib/window-helpers';
import { ifdescribe, ifit, listen, waitUntil } from './lib/spec-helpers';
import { once } from 'node:events';
@ -495,7 +495,7 @@ describe('app module', () => {
afterEach(() => closeWindow(w).then(() => { w = null as any; }));
it('should emit browser-window-focus event when window is focused', async () => {
const emitted = once(app, 'browser-window-focus');
const emitted = once(app, 'browser-window-focus') as Promise<[any, BrowserWindow]>;
w = new BrowserWindow({ show: false });
w.emit('focus');
const [, window] = await emitted;
@ -503,7 +503,7 @@ describe('app module', () => {
});
it('should emit browser-window-blur event when window is blurred', async () => {
const emitted = once(app, 'browser-window-blur');
const emitted = once(app, 'browser-window-blur') as Promise<[any, BrowserWindow]>;
w = new BrowserWindow({ show: false });
w.emit('blur');
const [, window] = await emitted;
@ -511,14 +511,14 @@ describe('app module', () => {
});
it('should emit browser-window-created event when window is created', async () => {
const emitted = once(app, 'browser-window-created');
const emitted = once(app, 'browser-window-created') as Promise<[any, BrowserWindow]>;
w = new BrowserWindow({ show: false });
const [, window] = await emitted;
expect(window.id).to.equal(w.id);
});
it('should emit web-contents-created event when a webContents is created', async () => {
const emitted = once(app, 'web-contents-created');
const emitted = once(app, 'web-contents-created') as Promise<[any, WebContents]>;
w = new BrowserWindow({ show: false });
const [, webContents] = await emitted;
expect(webContents.id).to.equal(w.webContents.id);
@ -535,7 +535,7 @@ describe('app module', () => {
});
await w.loadURL('about:blank');
const emitted = once(app, 'renderer-process-crashed');
const emitted = once(app, 'renderer-process-crashed') as Promise<[any, WebContents]>;
w.webContents.executeJavaScript('process.crash()');
const [, webContents] = await emitted;
@ -553,7 +553,7 @@ describe('app module', () => {
});
await w.loadURL('about:blank');
const emitted = once(app, 'render-process-gone');
const emitted = once(app, 'render-process-gone') as Promise<[any, WebContents, Electron.RenderProcessGoneDetails]>;
w.webContents.executeJavaScript('process.crash()');
const [, webContents, details] = await emitted;
@ -1935,7 +1935,7 @@ describe('default behavior', () => {
it('should emit a login event on app when a WebContents hits a 401', async () => {
const w = new BrowserWindow({ show: false });
w.loadURL(serverUrl);
const [, webContents] = await once(app, 'login');
const [, webContents] = await once(app, 'login') as [any, WebContents];
expect(webContents).to.equal(w.webContents);
});
});