mirror of https://github.com/sveltejs/svelte
parent
2e02868ef1
commit
578b5df23f
@ -0,0 +1,27 @@
|
|||||||
|
import { flushSync } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
async test({ assert, target, logs }) {
|
||||||
|
const checkboxes = target.querySelectorAll('input');
|
||||||
|
|
||||||
|
// input.value = '2';
|
||||||
|
// input.dispatchEvent(new window.Event('input'));
|
||||||
|
|
||||||
|
flushSync();
|
||||||
|
|
||||||
|
assert.htmlEqual(target.innerHTML, `<input type="checkbox" >`.repeat(3));
|
||||||
|
|
||||||
|
// assert.deepEqual(logs, ['b', '2', 'a', '2']);
|
||||||
|
|
||||||
|
flushSync(() => {
|
||||||
|
checkboxes.forEach((checkbox) => checkbox.click());
|
||||||
|
});
|
||||||
|
assert.deepEqual(logs, ['getBindings', ...repeatArray(3, ['check', false])]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/** @template T */
|
||||||
|
function repeatArray(/** @type {number} */ times = 1, /** @type {T[]} */ array) {
|
||||||
|
return /** @type {T[]} */ Array.from({ length: times }, () => array).flat();
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
<script>
|
||||||
|
let check = $state(true);
|
||||||
|
|
||||||
|
let check_bindings = [
|
||||||
|
() => check,
|
||||||
|
(v) => {
|
||||||
|
console.log('check', v);
|
||||||
|
check = v;
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
function getBindings() {
|
||||||
|
console.log('getBindings');
|
||||||
|
return check_bindings;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
<input type="checkbox" bind:checked={check_bindings[0], check_bindings[1]} />
|
||||||
|
|
||||||
|
<input type="checkbox" bind:checked={...check_bindings} />
|
||||||
|
|
||||||
|
<!-- <input type="checkbox" bind:checked={...check_bindings} /> -->
|
||||||
|
<input type="checkbox" bind:checked={...getBindings()} />
|
Loading…
Reference in new issue