|
1 |
| -import { tick } from 'svelte'; |
| 1 | +import { flushSync } from 'svelte'; |
2 | 2 |
|
3 |
| -import { ok, test } from '../../test'; |
| 3 | +import { test } from '../../test'; |
4 | 4 |
|
5 | 5 | export default test({
|
6 |
| - html: ` |
7 |
| - <div>false</div> |
8 |
| - <div>false</div> |
9 |
| - <input type="number"> |
10 |
| - <input type="number"> |
11 |
| - <button>click</button> |
12 |
| - `, |
13 |
| - |
14 |
| - ssrHtml: ` |
15 |
| - <div></div> |
16 |
| - <div></div> |
17 |
| - <input type="number"> |
18 |
| - <input type="number"> |
19 |
| - <button>click</button> |
20 |
| - `, |
21 |
| - |
22 | 6 | async test({ assert, component, target, window }) {
|
23 |
| - const [d1, d2] = target.querySelectorAll('div'); |
24 | 7 | const [in1, in2] = target.querySelectorAll('input');
|
25 |
| - const button = target.querySelector('button'); |
26 |
| - ok(in1); |
27 |
| - ok(in2); |
28 |
| - ok(button); |
29 |
| - ok(d1); |
30 |
| - ok(d2); |
31 |
| - assert.equal(d1.textContent, 'false'); |
32 |
| - assert.equal(d2.textContent, 'false'); |
33 |
| - const event1 = new window.MouseEvent('click', { bubbles: true }); |
34 |
| - in1.value = '1'; |
35 |
| - await in1.dispatchEvent(event1); |
36 |
| - await tick(); |
| 8 | + |
| 9 | + flushSync(() => in1.focus()); |
37 | 10 | assert.equal(window.document.activeElement, in1);
|
38 | 11 | assert.equal(component.a, true);
|
39 | 12 | assert.equal(component.b, false);
|
40 |
| - assert.equal(d1.textContent, 'true'); |
41 |
| - assert.equal(d2.textContent, 'false'); |
42 | 13 |
|
43 |
| - in2.value = '1'; |
44 |
| - const event2 = new window.MouseEvent('click', { bubbles: true }); |
45 |
| - await in2.dispatchEvent(event2); |
46 |
| - await tick(); |
| 14 | + flushSync(() => in2.focus()); |
| 15 | + assert.equal(window.document.activeElement, in2); |
47 | 16 | assert.equal(component.a, false);
|
48 | 17 | assert.equal(component.b, true);
|
49 |
| - assert.equal(d1.textContent, 'false'); |
50 |
| - assert.equal(d2.textContent, 'true'); |
51 |
| - |
52 |
| - const event3 = new window.MouseEvent('click', { bubbles: true }); |
53 |
| - await button.dispatchEvent(event3); |
54 |
| - await tick(); |
55 |
| - |
56 |
| - assert.equal(d1.textContent, 'false'); |
57 |
| - assert.equal(d2.textContent, 'false'); |
58 |
| - |
59 |
| - assert.htmlEqual( |
60 |
| - target.innerHTML, |
61 |
| - ` |
62 |
| - <div>false</div> |
63 |
| - <div>false</div> |
64 |
| - <input type="number"> |
65 |
| - <input type="number"> |
66 |
| - <button>click</button> |
67 |
| - ` |
68 |
| - ); |
69 | 18 | }
|
70 | 19 | });
|
0 commit comments