feat(types): improve page.evaluate types (#6193)

This commit is contained in:
Jack Franklin
2020-07-10 11:52:13 +01:00
committed by GitHub
parent 31309b0e20
commit 9b3005c105
32 changed files with 216 additions and 106 deletions

View File

@@ -36,7 +36,7 @@ describe('input tests', function () {
await page.goto(server.PREFIX + '/input/fileupload.html');
const filePath = path.relative(process.cwd(), FILE_TO_UPLOAD);
const input = await page.$('input');
await page.evaluate((e) => {
await page.evaluate((e: HTMLElement) => {
globalThis._inputEvents = [];
e.addEventListener('change', (ev) =>
globalThis._inputEvents.push(ev.type)
@@ -46,18 +46,18 @@ describe('input tests', function () {
);
}, input);
await input.uploadFile(filePath);
expect(await page.evaluate((e) => e.files[0].name, input)).toBe(
'file-to-upload.txt'
);
expect(await page.evaluate((e) => e.files[0].type, input)).toBe(
'text/plain'
);
expect(
await page.evaluate((e: HTMLInputElement) => e.files[0].name, input)
).toBe('file-to-upload.txt');
expect(
await page.evaluate((e: HTMLInputElement) => e.files[0].type, input)
).toBe('text/plain');
expect(await page.evaluate(() => globalThis._inputEvents)).toEqual([
'input',
'change',
]);
expect(
await page.evaluate((e) => {
await page.evaluate((e: HTMLInputElement) => {
const reader = new FileReader();
const promise = new Promise((fulfill) => (reader.onload = fulfill));
reader.readAsText(e.files[0]);