-
Notifications
You must be signed in to change notification settings - Fork 169
Expand file tree
/
Copy pathfocus.js
More file actions
26 lines (22 loc) · 1013 Bytes
/
focus.js
File metadata and controls
26 lines (22 loc) · 1013 Bytes
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
import {test, expect} from '../fixtures.js'
test.describe("the focus and blur commands", () => {
test("can focus an element", async ({html, find, evaluate}) => {
await html("<input id='i1' /><button _='on click focus #i1'></button>");
await find('button').dispatchEvent('click');
var focused = await evaluate(() => document.activeElement.id);
expect(focused).toBe("i1");
});
test("focus with no target focuses me", async ({html, find, evaluate}) => {
await html("<input id='i1' _='on click focus' />");
await find('#i1').dispatchEvent('click');
var focused = await evaluate(() => document.activeElement.id);
expect(focused).toBe("i1");
});
test("can blur an element", async ({html, find, evaluate}) => {
await html("<input id='i1' _='on focus wait 10ms then blur me' />");
await find('#i1').focus();
await find('#i1').evaluate(el => new Promise(r => setTimeout(r, 50)));
var focused = await evaluate(() => document.activeElement.tagName);
expect(focused).toBe("BODY");
});
});