test IIFE support

Jack Goodall 2 months ago
parent 59a96c9a97
commit c8294cc632

@ -5,14 +5,9 @@ export default test({
async test({ assert, target, logs }) { async test({ assert, target, logs }) {
const checkboxes = target.querySelectorAll('input'); const checkboxes = target.querySelectorAll('input');
// input.value = '2';
// input.dispatchEvent(new window.Event('input'));
flushSync(); flushSync();
assert.htmlEqual(target.innerHTML, `<input type="checkbox" >`.repeat(4)); assert.htmlEqual(target.innerHTML, `<input type="checkbox" >`.repeat(checkboxes.length));
// assert.deepEqual(logs, ['b', '2', 'a', '2']);
flushSync(() => { flushSync(() => {
checkboxes.forEach((checkbox) => checkbox.click()); checkboxes.forEach((checkbox) => checkbox.click());
@ -20,12 +15,12 @@ export default test({
assert.deepEqual(logs, [ assert.deepEqual(logs, [
'getArrayBindings', 'getArrayBindings',
'getObjectBindings', 'getObjectBindings',
...repeatArray(4, ['check', false]) ...repeatArray(checkboxes.length, ['check', false])
]); ]);
} }
}); });
/** @template T */ /** @template T */
function repeatArray(/** @type {number} */ times = 1, /** @type {T[]} */ array) { function repeatArray(/** @type {number} */ times, /** @type {T[]} */ array) {
return /** @type {T[]} */ Array.from({ length: times }, () => array).flat(); return /** @type {T[]} */ Array.from({ length: times }, () => array).flat();
} }

@ -28,4 +28,6 @@
<input type="checkbox" bind:checked={...getArrayBindings()} /> <input type="checkbox" bind:checked={...getArrayBindings()} />
<input type="checkbox" bind:checked={...(() => check_bindings)()} />
<input type="checkbox" bind:checked={...getObjectBindings()} /> <input type="checkbox" bind:checked={...getObjectBindings()} />

Loading…
Cancel
Save