-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
75 lines (61 loc) · 2.13 KB
/
index.test.js
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const query = require('./index.js');
it('finds labelled elements', async () => {
setTimeout(() => {
document.body.innerHTML =
'<label for="test-input">Test label</label>' +
'<input id="test-input" />' +
'';
}, 10);
expect(await query('Test label')).toBe(document.getElementById('test-input'));
});
it('finds titled elements', async () => {
setTimeout(() => {
document.body.innerHTML =
'<svg><title id="test-title">Test title</title></svg>' +
'';
}, 10);
expect(await query('Test title')).toBe(document.getElementById('test-title'));
});
it('finds elements by text content', async () => {
setTimeout(() => {
document.body.innerHTML =
'<button id="test-button">Test button</button>' +
'';
}, 10);
expect(await query('Test button')).toBe(document.getElementById('test-button'));
});
it('finds disabled elements', async () => {
document.body.innerHTML =
'<label for="test-input">Test label</label>' +
'<input id="test-input" />' +
'';
setTimeout(() => {
document.getElementById('test-input').setAttribute('disabled', '');
}, 10);
const node = await query('Test label', { disabled: '' });
expect(node).toBe(document.getElementById('test-input'));
expect(node.getAttribute('disabled')).toBe('');
});
it('finds input elements with a value', async () => {
document.body.innerHTML =
'<label for="test-input">Test label</label>' +
'<input id="test-input" />' +
'';
setTimeout(() => {
document.getElementById('test-input').setAttribute('value', 'test value');
}, 10);
const node = await query('Test label', { value: 'test value' });
expect(node).toBe(document.getElementById('test-input'));
expect(node.getAttribute('value')).toBe('test value');
});
it('finds elements with a role', async () => {
setTimeout(() => {
document.body.innerHTML =
'<label for="test-input">Test label</label>' +
'<input id="test-input" role="combobox" />' +
'';
}, 10);
const node = await query('Test label', { role: 'combobox' });
expect(node).toBe(document.getElementById('test-input'));
expect(node.getAttribute('role')).toBe('combobox');
});