test: use as const to remove some usages of as any (#39475)

This commit is contained in:
David Sanders 2023-08-14 18:24:32 -07:00 committed by GitHub
parent 9eeef55469
commit effafdf498
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 17 deletions

View file

@ -419,33 +419,33 @@ describe('session module', () => {
}); });
it('allows configuring proxy settings with mode `direct`', async () => { 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); await customSession.setProxy(config);
const proxy = await customSession.resolveProxy('http://example.com/'); const proxy = await customSession.resolveProxy('http://example.com/');
expect(proxy).to.equal('DIRECT'); expect(proxy).to.equal('DIRECT');
}); });
it('allows configuring proxy settings with mode `auto_detect`', async () => { 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); await customSession.setProxy(config);
}); });
it('allows configuring proxy settings with mode `pac_script`', async () => { 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); await customSession.setProxy(config);
const proxy = await customSession.resolveProxy('http://example.com/'); const proxy = await customSession.resolveProxy('http://example.com/');
expect(proxy).to.equal('DIRECT'); expect(proxy).to.equal('DIRECT');
}); });
it('allows configuring proxy settings with mode `fixed_servers`', async () => { 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); await customSession.setProxy(config);
const proxy = await customSession.resolveProxy('http://example.com/'); const proxy = await customSession.resolveProxy('http://example.com/');
expect(proxy).to.equal('PROXY myproxy:80'); expect(proxy).to.equal('PROXY myproxy:80');
}); });
it('allows configuring proxy settings with mode `system`', async () => { 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); await customSession.setProxy(config);
}); });
@ -468,7 +468,7 @@ describe('session module', () => {
res.end(pac); res.end(pac);
}); });
const { url } = await listen(server); 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); await customSession.setProxy(config);
{ {
const proxy = await customSession.resolveProxy('https://google.com'); const proxy = await customSession.resolveProxy('https://google.com');

View file

@ -29,7 +29,7 @@ describe('systemPreferences module', () => {
{ key: 'one', type: 'string', value: 'ONE' }, { key: 'one', type: 'string', value: 'ONE' },
{ key: 'two', value: 2, type: 'integer' }, { key: 'two', value: 2, type: 'integer' },
{ key: 'three', value: [1, 2, 3], type: 'array' } { key: 'three', value: [1, 2, 3], type: 'array' }
]; ] as const;
const defaultsDict: Record<string, any> = {}; const defaultsDict: Record<string, any> = {};
defaultsMap.forEach(row => { defaultsDict[row.key] = row.value; }); defaultsMap.forEach(row => { defaultsDict[row.key] = row.value; });
@ -38,7 +38,7 @@ describe('systemPreferences module', () => {
for (const userDefault of defaultsMap) { for (const userDefault of defaultsMap) {
const { key, value: expectedValue, type } = userDefault; 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); expect(actualValue).to.deep.equal(expectedValue);
} }
}); });
@ -91,12 +91,12 @@ describe('systemPreferences module', () => {
['url', 'https://github.com/electron'], ['url', 'https://github.com/electron'],
['array', [1, 2, 3]], ['array', [1, 2, 3]],
['dictionary', { a: 1, b: 2 }] ['dictionary', { a: 1, b: 2 }]
]; ] as const;
it('sets values', () => { it('sets values', () => {
for (const [type, value] of TEST_CASES) { for (const [type, value] of TEST_CASES) {
systemPreferences.setUserDefault(KEY, type as any, value as any); systemPreferences.setUserDefault(KEY, type, value as any);
const retrievedValue = systemPreferences.getUserDefault(KEY, type as any); const retrievedValue = systemPreferences.getUserDefault(KEY, type);
expect(retrievedValue).to.deep.equal(value); expect(retrievedValue).to.deep.equal(value);
} }
}); });
@ -104,7 +104,7 @@ describe('systemPreferences module', () => {
it('throws when type and value conflict', () => { it('throws when type and value conflict', () => {
for (const [type, value] of TEST_CASES) { for (const [type, value] of TEST_CASES) {
expect(() => { 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}`); }).to.throw(`Unable to convert value to: ${type}`);
} }
}); });
@ -158,10 +158,10 @@ describe('systemPreferences module', () => {
}); });
it('returns a valid system color', () => { 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 => { colors.forEach(color => {
const sysColor = systemPreferences.getSystemColor(color as any); const sysColor = systemPreferences.getSystemColor(color);
expect(sysColor).to.be.a('string'); expect(sysColor).to.be.a('string');
}); });
}); });

View file

@ -1280,9 +1280,9 @@ describe('webContents module', () => {
'default_public_interface_only', 'default_public_interface_only',
'default_public_and_private_interfaces', 'default_public_and_private_interfaces',
'disable_non_proxied_udp' 'disable_non_proxied_udp'
]; ] as const;
policies.forEach((policy) => { policies.forEach((policy) => {
w.webContents.setWebRTCIPHandlingPolicy(policy as any); w.webContents.setWebRTCIPHandlingPolicy(policy);
expect(w.webContents.getWebRTCIPHandlingPolicy()).to.equal(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]>; const promise = once(w.webContents, 'context-menu') as Promise<[any, Electron.ContextMenuParams]>;
// Simulate right-click to create context-menu event. // 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: 'mouseDown' });
w.webContents.sendInputEvent({ ...opts, type: 'mouseUp' }); w.webContents.sendInputEvent({ ...opts, type: 'mouseUp' });