-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathtest.ts
More file actions
44 lines (36 loc) · 1.3 KB
/
test.ts
File metadata and controls
44 lines (36 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { expect } from '@playwright/test';
import { sentryTest } from '../../../../../utils/fixtures';
sentryTest(
'wrapped callback should preserve correct context - window (not-bound)',
async ({ getLocalTestUrl, page }) => {
const url = await getLocalTestUrl({ testDir: __dirname });
await page.goto(url);
const { outsideCtx, requestAnimationFrameCtx } = (await page.evaluate(() => {
return new Promise(resolve => {
const outsideCtx = window as any;
requestAnimationFrame(function () {
// @ts-expect-error re-assigning this
resolve({ outsideCtx, requestAnimationFrameCtx: this });
});
});
})) as any;
expect(requestAnimationFrameCtx).toBe(outsideCtx);
},
);
sentryTest(
'wrapped callback should preserve correct context - `bind` bound method',
async ({ getLocalTestUrl, page }) => {
const url = await getLocalTestUrl({ testDir: __dirname });
await page.goto(url);
const requestAnimationFrameCtx = (await page.evaluate(() => {
return new Promise(resolve => {
function foo() {
// @ts-expect-error re-assigning this
resolve(this);
}
requestAnimationFrame(foo.bind({ magicNumber: 42 }));
});
})) as any;
expect(requestAnimationFrameCtx.magicNumber).toBe(42);
},
);