Skip to content

Commit 3c69f2a

Browse files
tes(types): use @ts-expect-error in tests where we check for errors (#3794)
1 parent e8cf895 commit 3c69f2a

15 files changed

+57
-29
lines changed

test/browsertype-launch-server.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ describe('lauch server', suite => {
4949
it('should fire close event', async ({browserType, defaultBrowserOptions}) => {
5050
const browserServer = await browserType.launchServer(defaultBrowserOptions);
5151
const [result] = await Promise.all([
52-
new Promise(f => (browserServer as any).on('close', (exitCode, signal) => f({ exitCode, signal }))),
52+
// @ts-expect-error The signal parameter is not documented.
53+
new Promise(f => browserServer.on('close', (exitCode, signal) => f({ exitCode, signal }))),
5354
browserServer.close(),
5455
]);
5556
expect(result['exitCode']).toBe(0);

test/browsertype-launch.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ it('should report launch log', test => {
9292
it('should accept objects as options', test => {
9393
test.slow();
9494
}, async ({browserType, defaultBrowserOptions}) => {
95-
const browser = await browserType.launch({ ...defaultBrowserOptions, process } as any);
95+
// @ts-expect-error process is not a real option.
96+
const browser = await browserType.launch({ ...defaultBrowserOptions, process });
9697
await browser.close();
9798
});
9899

test/chromium/session.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ describe('session', suite => {
4040
});
4141

4242
it('should only accept a page', async function({page}) {
43-
const error = await (page.context() as ChromiumBrowserContext).newCDPSession(page.context() as any).catch(e => e);
43+
// @ts-expect-error newCDPSession expects a Page
44+
const error = await (page.context() as ChromiumBrowserContext).newCDPSession(page.context()).catch(e => e);
4445
expect(error.message).toContain('page: expected Page');
4546
});
4647

@@ -84,7 +85,8 @@ describe('session', suite => {
8485
expect(error.message).toContain('ThisCommand.DoesNotExist');
8586

8687
async function theSourceOfTheProblems() {
87-
await client.send('ThisCommand.DoesNotExist' as any);
88+
// @ts-expect-error invalid command
89+
await client.send('ThisCommand.DoesNotExist');
8890
}
8991
});
9092

test/geolocation.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ it('should isolate contexts', async ({page, server, context, browser}) => {
7474
it('should throw with missing latitude', async ({context}) => {
7575
let error = null;
7676
try {
77-
await context.setGeolocation({longitude: 10} as any);
77+
// @ts-expect-error setGeolocation must have latitude
78+
await context.setGeolocation({longitude: 10});
7879
} catch (e) {
7980
error = e;
8081
}
@@ -93,7 +94,8 @@ it('should not modify passed default options object', async ({browser}) => {
9394
it('should throw with missing longitude in default options', async ({browser}) => {
9495
let error = null;
9596
try {
96-
const context = await browser.newContext({ geolocation: {latitude: 10} as any });
97+
// @ts-expect-error geolocation must have longitude
98+
const context = await browser.newContext({ geolocation: {latitude: 10} });
9799
await context.close();
98100
} catch (e) {
99101
error = e;

test/page-add-init-script.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ it('should work with content', async ({ page, server }) => {
3939
});
4040

4141
it('should throw without path and content', async ({ page, server }) => {
42-
const error = await page.addInitScript({ foo: 'bar' } as any).catch(e => e);
42+
// @ts-expect-error foo is not a real option of addInitScript
43+
const error = await page.addInitScript({ foo: 'bar' }).catch(e => e);
4344
expect(error.message).toContain('Either path or content property must be present');
4445
});
4546

test/page-emulate-media.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ it('should emulate type', async ({page, server}) => {
3434

3535
it('should throw in case of bad type argument', async ({page, server}) => {
3636
let error = null;
37-
await page.emulateMedia({ media: 'bad' as any}).catch(e => error = e);
37+
// @ts-expect-error 'bad' is not a valid media type
38+
await page.emulateMedia({ media: 'bad'}).catch(e => error = e);
3839
expect(error.message).toContain('media: expected one of (screen|print|null)');
3940
});
4041

@@ -62,7 +63,8 @@ it('should default to light', async ({page, server}) => {
6263

6364
it('should throw in case of bad argument', async ({page, server}) => {
6465
let error = null;
65-
await page.emulateMedia({ colorScheme: 'bad' as any}).catch(e => error = e);
66+
// @ts-expect-error 'bad' is not a valid media type
67+
await page.emulateMedia({ colorScheme: 'bad' }).catch(e => error = e);
6668
expect(error.message).toContain('colorScheme: expected one of (dark|light|no-preference|null)');
6769
});
6870

test/page-fill.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ it('should throw when element is not an <input>, <textarea> or [contenteditable]
138138
it('should throw if passed a non-string value', async ({page, server}) => {
139139
let error = null;
140140
await page.goto(server.PREFIX + '/input/textarea.html');
141-
await page.fill('textarea', 123 as any).catch(e => error = e);
141+
// @ts-expect-error fill only accepts string values
142+
await page.fill('textarea', 123).catch(e => error = e);
142143
expect(error.message).toContain('value: expected string, got number');
143144
});
144145

test/page-goto.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,14 @@ it('should not crash when navigating to bad SSL after a cross origin navigation'
199199
});
200200

201201
it('should not throw if networkidle0 is passed as an option', async ({page, server}) => {
202-
await page.goto(server.EMPTY_PAGE, {waitUntil: 'networkidle0' as any});
202+
// @ts-expect-error networkidle0 is undocumented
203+
await page.goto(server.EMPTY_PAGE, {waitUntil: 'networkidle0'});
203204
});
204205

205206
it('should throw if networkidle2 is passed as an option', async ({page, server}) => {
206207
let error = null;
207-
await page.goto(server.EMPTY_PAGE, {waitUntil: 'networkidle2' as any}).catch(err => error = err);
208+
// @ts-expect-error networkidle2 is not allowed
209+
await page.goto(server.EMPTY_PAGE, {waitUntil: 'networkidle2'}).catch(err => error = err);
208210
expect(error.message).toContain(`waitUntil: expected one of (load|domcontentloaded|networkidle)`);
209211
});
210212

test/page-select-option.spec.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,31 +175,35 @@ it('should throw if passed wrong types', async ({page, server}) => {
175175

176176
error = null;
177177
try {
178-
await page.selectOption('select', 12 as any);
178+
// @ts-expect-error cannot select numbers
179+
await page.selectOption('select', 12);
179180
} catch (e) {
180181
error = e;
181182
}
182183
expect(error.message).toContain('options[0]: expected object, got number');
183184

184185
error = null;
185186
try {
186-
await page.selectOption('select', { value: 12 } as any);
187+
// @ts-expect-error cannot select numbers
188+
await page.selectOption('select', { value: 12 });
187189
} catch (e) {
188190
error = e;
189191
}
190192
expect(error.message).toContain('options[0].value: expected string, got number');
191193

192194
error = null;
193195
try {
194-
await page.selectOption('select', { label: 12 } as any);
196+
// @ts-expect-error cannot select numbers
197+
await page.selectOption('select', { label: 12 });
195198
} catch (e) {
196199
error = e;
197200
}
198201
expect(error.message).toContain('options[0].label: expected string, got number');
199202

200203
error = null;
201204
try {
202-
await page.selectOption('select', { index: '12' } as any);
205+
// @ts-expect-error cannot select string indices
206+
await page.selectOption('select', { index: '12' });
203207
} catch (e) {
204208
error = e;
205209
}

test/page-set-extra-http-headers.spec.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,12 @@ it('should override extra headers from browser context', async ({browser, server
7474
});
7575

7676
it('should throw for non-string header values', async ({browser, page}) => {
77-
const error1 = await page.setExtraHTTPHeaders({ 'foo': 1 as any }).catch(e => e);
77+
// @ts-expect-error headers must be strings
78+
const error1 = await page.setExtraHTTPHeaders({ 'foo': 1 }).catch(e => e);
7879
expect(error1.message).toContain('Expected value of header "foo" to be String, but "number" is found.');
79-
const error2 = await page.context().setExtraHTTPHeaders({ 'foo': true as any }).catch(e => e);
80+
// @ts-expect-error headers must be strings
81+
const error2 = await page.context().setExtraHTTPHeaders({ 'foo': true }).catch(e => e);
8082
expect(error2.message).toContain('Expected value of header "foo" to be String, but "boolean" is found.');
81-
const error3 = await browser.newContext({ extraHTTPHeaders: { 'foo': null as any } }).catch(e => e);
83+
const error3 = await browser.newContext({ extraHTTPHeaders: { 'foo': null } }).catch(e => e);
8284
expect(error3.message).toContain('Expected value of header "foo" to be String, but "object" is found.');
8385
});

0 commit comments

Comments
 (0)