Skip to content

Commit 4540c26

Browse files
committed
simplify test
1 parent 412e3c0 commit 4540c26

File tree

2 files changed

+9
-62
lines changed

2 files changed

+9
-62
lines changed
Lines changed: 6 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,19 @@
1-
import { tick } from 'svelte';
1+
import { flushSync } from 'svelte';
22

3-
import { ok, test } from '../../test';
3+
import { test } from '../../test';
44

55
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-
226
async test({ assert, component, target, window }) {
23-
const [d1, d2] = target.querySelectorAll('div');
247
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());
3710
assert.equal(window.document.activeElement, in1);
3811
assert.equal(component.a, true);
3912
assert.equal(component.b, false);
40-
assert.equal(d1.textContent, 'true');
41-
assert.equal(d2.textContent, 'false');
4213

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);
4716
assert.equal(component.a, false);
4817
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-
);
6918
}
7019
});

packages/svelte/tests/runtime-legacy/samples/binding-focused/main.svelte

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
export let a;
33
export let b;
44
</script>
5-
<div>{a}</div>
6-
<div>{b}</div>
7-
<input type="number" bind:focused={a} onclick='{e => e.target.focus()}' />
8-
<input type="number" bind:focused={b} onclick='{e => e.target.focus()}' />
9-
<button onclick='{e => e.target.focus()}'>click</button>
5+
6+
<input bind:focused={a} />
7+
<input bind:focused={b} />

0 commit comments

Comments
 (0)