mirror of https://github.com/sveltejs/svelte
parent
63d87445db
commit
02d23d1bf0
@ -0,0 +1,27 @@
|
|||||||
|
import { flushSync } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
html: '<div class="base">content</div> <button>toggle</button>',
|
||||||
|
test({ assert, target, serialize, dispatch_event }) {
|
||||||
|
const button = target.children.find(
|
||||||
|
(/**@type {any} */ n) => n.type === 'element' && n.name === 'button'
|
||||||
|
);
|
||||||
|
assert.ok(button);
|
||||||
|
|
||||||
|
// Click to add the "active" class
|
||||||
|
dispatch_event(button, 'click');
|
||||||
|
flushSync();
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
serialize(target),
|
||||||
|
'<div class="base active">content</div> <button>toggle</button>'
|
||||||
|
);
|
||||||
|
|
||||||
|
// Click again to remove the "active" class
|
||||||
|
dispatch_event(button, 'click');
|
||||||
|
flushSync();
|
||||||
|
|
||||||
|
assert.equal(serialize(target), '<div class="base">content</div> <button>toggle</button>');
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
<script>
|
||||||
|
let active = $state(false);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="base" class:active>content</div>
|
||||||
|
<button onclick={() => active = !active}>toggle</button>
|
||||||
Loading…
Reference in new issue