chore: fix `$props.id` tests

pull/15294/head
paoloricciuti 7 months ago
parent b6bf735a23
commit 868e3fa56e

@ -3,59 +3,25 @@ import { test } from '../../test';
export default test({ export default test({
test({ assert, target, variant }) { test({ assert, target, variant }) {
if (variant === 'dom') { const ps = [...target.querySelectorAll('p')].map((p) => p.innerHTML);
assert.htmlEqual( const unique = new Set(ps);
target.innerHTML, assert.equal(ps.length, unique.size);
`
<button>toggle</button> if (variant === 'hydrate') {
<h1>c1</h1> const start = ps.map((p) => p.substring(0, 1));
<p>c2</p> assert.deepEqual(start, ['s', 's', 's', 's']);
<p>c3</p>
<p>c4</p>
`
);
} else {
assert.htmlEqual(
target.innerHTML,
`
<button>toggle</button>
<h1>s1</h1>
<p>s2</p>
<p>s3</p>
<p>s4</p>
`
);
} }
let button = target.querySelector('button'); let button = target.querySelector('button');
flushSync(() => button?.click()); flushSync(() => button?.click());
if (variant === 'dom') { const ps_after = [...target.querySelectorAll('p')].map((p) => p.innerHTML);
assert.htmlEqual( const unique_after = new Set(ps_after);
target.innerHTML, assert.equal(ps_after.length, unique_after.size);
`
<button>toggle</button> if (variant === 'hydrate') {
<h1>c1</h1> const start = ps_after.map((p) => p.substring(0, 1));
<p>c2</p> assert.deepEqual(start, ['s', 's', 's', 's', 'c']);
<p>c3</p>
<p>c4</p>
<p>c5</p>
`
);
} else {
// `c6` because this runs after the `dom` tests
// (slightly brittle but good enough for now)
assert.htmlEqual(
target.innerHTML,
`
<button>toggle</button>
<h1>s1</h1>
<p>s2</p>
<p>s3</p>
<p>s4</p>
<p>c6</p>
`
);
} }
} }
}); });

@ -8,7 +8,7 @@
<button onclick={() => show = !show}>toggle</button> <button onclick={() => show = !show}>toggle</button>
<h1>{id}</h1> <p>{id}</p>
<Child /> <Child />
<Child /> <Child />

Loading…
Cancel
Save