test: use as const to remove some usages of as any (#39475)
This commit is contained in:
parent
9eeef55469
commit
effafdf498
3 changed files with 17 additions and 17 deletions
|
@ -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');
|
||||
|
|
|
@ -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<string, any> = {};
|
||||
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');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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' });
|
||||
|
||||
|
|
Loading…
Reference in a new issue