test: cleanup let xyz = null as unknown as T; (#37335)

This commit is contained in:
Milan Burda 2023-02-19 10:24:24 +01:00 committed by GitHub
parent fcfbcbc7e1
commit cf10c19c33
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 41 additions and 41 deletions

View file

@ -95,7 +95,7 @@ describe('BrowserWindow module', () => {
});
describe('BrowserWindow.close()', () => {
let w = null as unknown as BrowserWindow;
let w: BrowserWindow;
beforeEach(() => {
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
});
@ -150,8 +150,8 @@ describe('BrowserWindow module', () => {
});
describe('when invoked synchronously inside navigation observer', () => {
let server: http.Server = null as unknown as http.Server;
let url: string = null as unknown as string;
let server: http.Server;
let url: string;
before((done) => {
server = http.createServer((request, response) => {
@ -210,7 +210,7 @@ describe('BrowserWindow module', () => {
});
describe('window.close()', () => {
let w = null as unknown as BrowserWindow;
let w: BrowserWindow;
beforeEach(() => {
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
});
@ -236,7 +236,7 @@ describe('BrowserWindow module', () => {
});
describe('BrowserWindow.destroy()', () => {
let w = null as unknown as BrowserWindow;
let w: BrowserWindow;
beforeEach(() => {
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } });
});
@ -274,7 +274,7 @@ describe('BrowserWindow module', () => {
});
describe('BrowserWindow.loadURL(url)', () => {
let w = null as unknown as BrowserWindow;
let w: BrowserWindow;
const scheme = 'other';
const srcPath = path.join(fixtures, 'api', 'loaded-from-dataurl.js');
before(() => {
@ -294,8 +294,8 @@ describe('BrowserWindow module', () => {
await closeWindow(w);
w = null as unknown as BrowserWindow;
});
let server = null as unknown as http.Server;
let url = null as unknown as string;
let server: http.Server;
let url: string;
let postData = null as any;
before((done) => {
const filePath = path.join(fixtures, 'pages', 'a.html');
@ -474,7 +474,7 @@ describe('BrowserWindow module', () => {
for (const sandbox of [false, true]) {
describe(`navigation events${sandbox ? ' with sandbox' : ''}`, () => {
let w = null as unknown as BrowserWindow;
let w: BrowserWindow;
beforeEach(() => {
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: false, sandbox } });
});
@ -484,8 +484,8 @@ describe('BrowserWindow module', () => {
});
describe('will-navigate event', () => {
let server = null as unknown as http.Server;
let url = null as unknown as string;
let server: http.Server;
let url: string;
before((done) => {
server = http.createServer((req, res) => {
if (req.url === '/navigate-top') {
@ -592,8 +592,8 @@ describe('BrowserWindow module', () => {
});
describe('will-redirect event', () => {
let server = null as unknown as http.Server;
let url = null as unknown as string;
let server: http.Server;
let url: string;
before((done) => {
server = http.createServer((req, res) => {
if (req.url === '/302') {
@ -683,7 +683,7 @@ describe('BrowserWindow module', () => {
}
describe('focus and visibility', () => {
let w = null as unknown as BrowserWindow;
let w: BrowserWindow;
beforeEach(() => {
w = new BrowserWindow({ show: false });
});
@ -1015,7 +1015,7 @@ describe('BrowserWindow module', () => {
});
describe('sizing', () => {
let w = null as unknown as BrowserWindow;
let w: BrowserWindow;
beforeEach(() => {
w = new BrowserWindow({ show: false, width: 400, height: 400 });
@ -1617,7 +1617,7 @@ describe('BrowserWindow module', () => {
});
ifdescribe(process.platform === 'darwin')('tabbed windows', () => {
let w = null as unknown as BrowserWindow;
let w: BrowserWindow;
beforeEach(() => {
w = new BrowserWindow({ show: false });
});
@ -1810,7 +1810,7 @@ describe('BrowserWindow module', () => {
});
describe('BrowserWindow.setProgressBar(progress)', () => {
let w = null as unknown as BrowserWindow;
let w: BrowserWindow;
before(() => {
w = new BrowserWindow({ show: false });
});
@ -1849,7 +1849,7 @@ describe('BrowserWindow module', () => {
});
describe('BrowserWindow.setAlwaysOnTop(flag, level)', () => {
let w = null as unknown as BrowserWindow;
let w: BrowserWindow;
afterEach(closeAllWindows);
@ -1897,10 +1897,10 @@ describe('BrowserWindow module', () => {
});
describe('preconnect feature', () => {
let w = null as unknown as BrowserWindow;
let w: BrowserWindow;
let server = null as unknown as http.Server;
let url = null as unknown as string;
let server: http.Server;
let url: string;
let connections = 0;
beforeEach(async () => {
@ -1951,7 +1951,7 @@ describe('BrowserWindow module', () => {
});
describe('BrowserWindow.setAutoHideCursor(autoHide)', () => {
let w = null as unknown as BrowserWindow;
let w: BrowserWindow;
beforeEach(() => {
w = new BrowserWindow({ show: false });
});
@ -2941,8 +2941,8 @@ describe('BrowserWindow module', () => {
describe('"sandbox" option', () => {
const preload = path.join(path.resolve(__dirname, 'fixtures'), 'module', 'preload-sandbox.js');
let server: http.Server = null as unknown as http.Server;
let serverUrl: string = null as unknown as string;
let server: http.Server;
let serverUrl: string;
before((done) => {
server = http.createServer((request, response) => {
@ -3213,7 +3213,7 @@ describe('BrowserWindow module', () => {
});
describe('event handling', () => {
let w: BrowserWindow = null as unknown as BrowserWindow;
let w: BrowserWindow;
beforeEach(() => {
w = new BrowserWindow({ show: false, webPreferences: { sandbox: true } });
});
@ -3314,7 +3314,7 @@ describe('BrowserWindow module', () => {
});
describe('child windows', () => {
let w: BrowserWindow = null as unknown as BrowserWindow;
let w: BrowserWindow;
beforeEach(() => {
w = new BrowserWindow({
@ -3514,7 +3514,7 @@ describe('BrowserWindow module', () => {
});
describe('beforeunload handler', function () {
let w: BrowserWindow = null as unknown as BrowserWindow;
let w: BrowserWindow;
beforeEach(() => {
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } });
});
@ -4472,8 +4472,8 @@ describe('BrowserWindow module', () => {
});
describe('loading main frame state', () => {
let server: http.Server = null as unknown as http.Server;
let serverUrl: string = null as unknown as string;
let server: http.Server;
let serverUrl: string;
before((done) => {
server = http.createServer((request, response) => {

View file

@ -13,7 +13,7 @@ const fixturesPath = path.resolve(__dirname, 'fixtures');
describe('ipc module', () => {
describe('invoke', () => {
let w = (null as unknown as BrowserWindow);
let w: BrowserWindow;
before(async () => {
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
@ -127,7 +127,7 @@ describe('ipc module', () => {
});
describe('ordering', () => {
let w = (null as unknown as BrowserWindow);
let w: BrowserWindow;
before(async () => {
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });

View file

@ -70,7 +70,7 @@ function defer (): Promise<any> & {resolve: Function, reject: Function} {
}
describe('protocol module', () => {
let contents: WebContents = null as unknown as WebContents;
let contents: WebContents;
// NB. sandbox: true is used because it makes navigations much (~8x) faster.
before(() => { contents = (webContents as typeof ElectronInternal.WebContents).create({ sandbox: true }); });
after(() => contents.destroy());
@ -824,7 +824,7 @@ describe('protocol module', () => {
const imageURL = `${origin}/test.png`;
const filePath = path.join(fixturesPath, 'pages', 'b.html');
const fileContent = '<img src="/test.png" />';
let w: BrowserWindow = null as unknown as BrowserWindow;
let w: BrowserWindow;
beforeEach(() => {
w = new BrowserWindow({
@ -900,7 +900,7 @@ describe('protocol module', () => {
});
describe('protocol.registerSchemesAsPrivileged cors-fetch', function () {
let w: BrowserWindow = null as unknown as BrowserWindow;
let w: BrowserWindow;
beforeEach(async () => {
w = new BrowserWindow({ show: false });
});
@ -1005,7 +1005,7 @@ describe('protocol module', () => {
const pagePath = path.join(fixturesPath, 'pages', 'video.html');
const videoSourceImagePath = path.join(fixturesPath, 'video-source-image.webp');
const videoPath = path.join(fixturesPath, 'video.webm');
let w: BrowserWindow = null as unknown as BrowserWindow;
let w: BrowserWindow;
before(async () => {
// generate test video

View file

@ -13,7 +13,7 @@ describe('session.serviceWorkers', () => {
let ses: Electron.Session;
let server: http.Server;
let baseUrl: string;
let w: WebContents = null as unknown as WebContents;
let w: WebContents;
before(async () => {
ses = session.fromPartition(partition);

View file

@ -292,8 +292,8 @@ describe('webContents module', () => {
});
afterEach(closeAllWindows);
let server: http.Server = null as unknown as http.Server;
let serverUrl: string = null as unknown as string;
let server: http.Server;
let serverUrl: string;
before((done) => {
server = http.createServer((request, response) => {

View file

@ -49,7 +49,7 @@ describe('webRequest module', () => {
protocol.unregisterProtocol('cors');
});
let contents: WebContents = null as unknown as WebContents;
let contents: WebContents;
// NB. sandbox: true is used because it makes navigations much (~8x) faster.
before(async () => {
contents = (webContents as typeof ElectronInternal.WebContents).create({ sandbox: true });

View file

@ -97,8 +97,8 @@ describe('window.postMessage', () => {
});
describe('focus handling', () => {
let webviewContents: WebContents = null as unknown as WebContents;
let w: BrowserWindow = null as unknown as BrowserWindow;
let webviewContents: WebContents;
let w: BrowserWindow;
beforeEach(async () => {
w = new BrowserWindow({