From effafdf49860b828a031ee92eb272a6851da3ebe Mon Sep 17 00:00:00 2001 From: David Sanders Date: Mon, 14 Aug 2023 18:24:32 -0700 Subject: [PATCH] test: use as const to remove some usages of as any (#39475) --- spec/api-session-spec.ts | 12 ++++++------ spec/api-system-preferences-spec.ts | 16 ++++++++-------- spec/api-web-contents-spec.ts | 6 +++--- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/spec/api-session-spec.ts b/spec/api-session-spec.ts index 840748167a24..592d43eb6982 100644 --- a/spec/api-session-spec.ts +++ b/spec/api-session-spec.ts @@ -419,33 +419,33 @@ describe('session module', () => { }); it('allows configuring proxy settings with mode `direct`', async () => { - const config = { mode: 'direct' as any, proxyRules: 'http=myproxy:80' }; + const config = { mode: 'direct' as const, proxyRules: 'http=myproxy:80' }; await customSession.setProxy(config); const proxy = await customSession.resolveProxy('http://example.com/'); expect(proxy).to.equal('DIRECT'); }); it('allows configuring proxy settings with mode `auto_detect`', async () => { - const config = { mode: 'auto_detect' as any }; + const config = { mode: 'auto_detect' as const }; await customSession.setProxy(config); }); it('allows configuring proxy settings with mode `pac_script`', async () => { - const config = { mode: 'pac_script' as any }; + const config = { mode: 'pac_script' as const }; await customSession.setProxy(config); const proxy = await customSession.resolveProxy('http://example.com/'); expect(proxy).to.equal('DIRECT'); }); it('allows configuring proxy settings with mode `fixed_servers`', async () => { - const config = { mode: 'fixed_servers' as any, proxyRules: 'http=myproxy:80' }; + const config = { mode: 'fixed_servers' as const, proxyRules: 'http=myproxy:80' }; await customSession.setProxy(config); const proxy = await customSession.resolveProxy('http://example.com/'); expect(proxy).to.equal('PROXY myproxy:80'); }); it('allows configuring proxy settings with mode `system`', async () => { - const config = { mode: 'system' as any }; + const config = { mode: 'system' as const }; await customSession.setProxy(config); }); @@ -468,7 +468,7 @@ describe('session module', () => { res.end(pac); }); const { url } = await listen(server); - const config = { mode: 'pac_script' as any, pacScript: url }; + const config = { mode: 'pac_script' as const, pacScript: url }; await customSession.setProxy(config); { const proxy = await customSession.resolveProxy('https://google.com'); diff --git a/spec/api-system-preferences-spec.ts b/spec/api-system-preferences-spec.ts index 6a9395f5e986..ab4f33b171be 100644 --- a/spec/api-system-preferences-spec.ts +++ b/spec/api-system-preferences-spec.ts @@ -29,7 +29,7 @@ describe('systemPreferences module', () => { { key: 'one', type: 'string', value: 'ONE' }, { key: 'two', value: 2, type: 'integer' }, { key: 'three', value: [1, 2, 3], type: 'array' } - ]; + ] as const; const defaultsDict: Record = {}; defaultsMap.forEach(row => { defaultsDict[row.key] = row.value; }); @@ -38,7 +38,7 @@ describe('systemPreferences module', () => { for (const userDefault of defaultsMap) { const { key, value: expectedValue, type } = userDefault; - const actualValue = systemPreferences.getUserDefault(key, type as any); + const actualValue = systemPreferences.getUserDefault(key, type); expect(actualValue).to.deep.equal(expectedValue); } }); @@ -91,12 +91,12 @@ describe('systemPreferences module', () => { ['url', 'https://github.com/electron'], ['array', [1, 2, 3]], ['dictionary', { a: 1, b: 2 }] - ]; + ] as const; it('sets values', () => { for (const [type, value] of TEST_CASES) { - systemPreferences.setUserDefault(KEY, type as any, value as any); - const retrievedValue = systemPreferences.getUserDefault(KEY, type as any); + systemPreferences.setUserDefault(KEY, type, value as any); + const retrievedValue = systemPreferences.getUserDefault(KEY, type); expect(retrievedValue).to.deep.equal(value); } }); @@ -104,7 +104,7 @@ describe('systemPreferences module', () => { it('throws when type and value conflict', () => { for (const [type, value] of TEST_CASES) { expect(() => { - systemPreferences.setUserDefault(KEY, type as any, typeof value === 'string' ? {} : 'foo' as any); + systemPreferences.setUserDefault(KEY, type, typeof value === 'string' ? {} : 'foo' as any); }).to.throw(`Unable to convert value to: ${type}`); } }); @@ -158,10 +158,10 @@ describe('systemPreferences module', () => { }); it('returns a valid system color', () => { - const colors = ['blue', 'brown', 'gray', 'green', 'orange', 'pink', 'purple', 'red', 'yellow']; + const colors = ['blue', 'brown', 'gray', 'green', 'orange', 'pink', 'purple', 'red', 'yellow'] as const; colors.forEach(color => { - const sysColor = systemPreferences.getSystemColor(color as any); + const sysColor = systemPreferences.getSystemColor(color); expect(sysColor).to.be.a('string'); }); }); diff --git a/spec/api-web-contents-spec.ts b/spec/api-web-contents-spec.ts index aeb2a1134988..38f77ece9460 100644 --- a/spec/api-web-contents-spec.ts +++ b/spec/api-web-contents-spec.ts @@ -1280,9 +1280,9 @@ describe('webContents module', () => { 'default_public_interface_only', 'default_public_and_private_interfaces', 'disable_non_proxied_udp' - ]; + ] as const; policies.forEach((policy) => { - w.webContents.setWebRTCIPHandlingPolicy(policy as any); + w.webContents.setWebRTCIPHandlingPolicy(policy); expect(w.webContents.getWebRTCIPHandlingPolicy()).to.equal(policy); }); }); @@ -2254,7 +2254,7 @@ describe('webContents module', () => { const promise = once(w.webContents, 'context-menu') as Promise<[any, Electron.ContextMenuParams]>; // Simulate right-click to create context-menu event. - const opts = { x: 0, y: 0, button: 'right' as any }; + const opts = { x: 0, y: 0, button: 'right' as const }; w.webContents.sendInputEvent({ ...opts, type: 'mouseDown' }); w.webContents.sendInputEvent({ ...opts, type: 'mouseUp' });