mirror of https://github.com/sveltejs/svelte
parent
b49cd79bc4
commit
b4202bc636
@ -1,20 +1,18 @@
|
||||
import { test } from '../../test';
|
||||
import { log, handler, log_a } from './event.js';
|
||||
|
||||
export default test({
|
||||
before_test() {
|
||||
log.length = 0;
|
||||
handler.value = log_a;
|
||||
},
|
||||
|
||||
async test({ assert, target }) {
|
||||
const [b1, b2] = target.querySelectorAll('button');
|
||||
async test({ assert, logs, target, component }) {
|
||||
const [b1, b2, b3] = target.querySelectorAll('button');
|
||||
|
||||
b1?.click();
|
||||
assert.deepEqual(log, ['a']);
|
||||
assert.deepEqual(logs, ['a']);
|
||||
|
||||
b2?.click();
|
||||
b1?.click();
|
||||
assert.deepEqual(log, ['a', 'b']);
|
||||
|
||||
b3?.click();
|
||||
b1?.click();
|
||||
|
||||
assert.deepEqual(logs, ['a', 'b', 'a']);
|
||||
}
|
||||
});
|
||||
|
||||
@ -1,14 +0,0 @@
|
||||
/** @type {any[]} */
|
||||
export const log = [];
|
||||
|
||||
export const log_a = () => {
|
||||
log.push('a');
|
||||
};
|
||||
|
||||
export const log_b = () => {
|
||||
log.push('b');
|
||||
};
|
||||
|
||||
export const handler = {
|
||||
value: log_a
|
||||
};
|
||||
@ -0,0 +1,22 @@
|
||||
<script context="module">
|
||||
|
||||
export const log_a = () => {
|
||||
console.log('a');
|
||||
};
|
||||
|
||||
export const log_b = () => {
|
||||
console.log('b');
|
||||
};
|
||||
|
||||
let handle = $state(log_a);
|
||||
|
||||
export const handler = {
|
||||
get value() {
|
||||
return handle;
|
||||
},
|
||||
set value(v) {
|
||||
handle = v;
|
||||
}
|
||||
};
|
||||
|
||||
</script>
|
||||
@ -1,6 +1,7 @@
|
||||
<script>
|
||||
import {handler, log_b} from './event.js';
|
||||
import {handler, log_a, log_b} from './event.svelte';
|
||||
</script>
|
||||
|
||||
<button onclick={handler.value}>click</button>
|
||||
<button onclick={() => handler.value = log_b}>change</button>
|
||||
<button onclick={() => handler.value = log_a}>change back</button>
|
||||
|
||||
Loading…
Reference in new issue