Skip to content

Commit 3350db2

Browse files
authored
chore: nit test fixes (#4114)
1 parent c2adc98 commit 3350db2

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

test/browsercontext-expose-function.spec.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
*/
1717
import { it, expect } from './fixtures';
1818

19-
it('expose binding should work', async ({browser}) => {
20-
const context = await browser.newContext();
19+
it('expose binding should work', async ({context}) => {
2120
let bindingSource;
2221
await context.exposeBinding('add', (source, a, b) => {
2322
bindingSource = source;
@@ -29,11 +28,9 @@ it('expose binding should work', async ({browser}) => {
2928
expect(bindingSource.page).toBe(page);
3029
expect(bindingSource.frame).toBe(page.mainFrame());
3130
expect(result).toEqual(11);
32-
await context.close();
3331
});
3432

35-
it('should work', async ({browser, server}) => {
36-
const context = await browser.newContext();
33+
it('should work', async ({context, server}) => {
3734
await context.exposeFunction('add', (a, b) => a + b);
3835
const page = await context.newPage();
3936
await page.exposeFunction('mul', (a, b) => a * b);
@@ -44,11 +41,9 @@ it('should work', async ({browser, server}) => {
4441
});
4542
const result = await page.evaluate('(async () => ({ mul: await mul(9, 4), add: await add(9, 4), sub: await sub(9, 4), addHandle: await addHandle(5, 6) }))()');
4643
expect(result).toEqual({ mul: 36, add: 13, sub: 5, addHandle: 11 });
47-
await context.close();
4844
});
4945

50-
it('should throw for duplicate registrations', async ({browser, server}) => {
51-
const context = await browser.newContext();
46+
it('should throw for duplicate registrations', async ({context, server}) => {
5247
await context.exposeFunction('foo', () => {});
5348
await context.exposeFunction('bar', () => {});
5449
let error = await context.exposeFunction('foo', () => {}).catch(e => e);
@@ -59,11 +54,9 @@ it('should throw for duplicate registrations', async ({browser, server}) => {
5954
await page.exposeFunction('baz', () => {});
6055
error = await context.exposeFunction('baz', () => {}).catch(e => e);
6156
expect(error.message).toContain('Function "baz" has been already registered in one of the pages');
62-
await context.close();
6357
});
6458

65-
it('should be callable from-inside addInitScript', async ({browser, server}) => {
66-
const context = await browser.newContext();
59+
it('should be callable from-inside addInitScript', async ({context, server}) => {
6760
let args = [];
6861
await context.exposeFunction('woof', function(arg) {
6962
args.push(arg);
@@ -74,11 +67,9 @@ it('should be callable from-inside addInitScript', async ({browser, server}) =>
7467
args = [];
7568
await page.reload();
7669
expect(args).toEqual(['context', 'page']);
77-
await context.close();
7870
});
7971

80-
it('exposeBindingHandle should work', async ({browser}) => {
81-
const context = await browser.newContext();
72+
it('exposeBindingHandle should work', async ({context}) => {
8273
let target;
8374
await context.exposeBinding('logme', (source, t) => {
8475
target = t;
@@ -90,5 +81,4 @@ it('exposeBindingHandle should work', async ({browser}) => {
9081
});
9182
expect(await target.evaluate(x => x.foo)).toBe(42);
9283
expect(result).toEqual(17);
93-
await context.close();
9484
});

0 commit comments

Comments
 (0)