forked from sveltejs/svelte
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix event handlers that are dynamic via reactive declarations or stor…
…es (sveltejs#4394)
- Loading branch information
1 parent
98aba12
commit 00f71a3
Showing
4 changed files
with
54 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
export default { | ||
html: ` | ||
<button>toggle</button> | ||
<p>0</p> | ||
<button>handler_a</button> | ||
<button>handler_b</button> | ||
`, | ||
|
||
async test({ assert, target, window }) { | ||
const [toggle, handler_a, handler_b] = target.querySelectorAll('button'); | ||
const p = target.querySelector('p'); | ||
|
||
const event = new window.MouseEvent('click'); | ||
|
||
await handler_a.dispatchEvent(event); | ||
assert.equal(p.innerHTML, '1'); | ||
|
||
await toggle.dispatchEvent(event); | ||
|
||
await handler_a.dispatchEvent(event); | ||
assert.equal(p.innerHTML, '2'); | ||
|
||
await toggle.dispatchEvent(event); | ||
|
||
await handler_b.dispatchEvent(event); | ||
assert.equal(p.innerHTML, '1'); | ||
|
||
await toggle.dispatchEvent(event); | ||
|
||
await handler_b.dispatchEvent(event); | ||
assert.equal(p.innerHTML, '2'); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<script> | ||
import { writable } from 'svelte/store'; | ||
let number = 0; | ||
const handler_1 = () => number = 1; | ||
const handler_2 = () => number = 2; | ||
let flag = true; | ||
$: handler_a = flag ? handler_1 : handler_2; | ||
const handler_b = writable(); | ||
$: handler_b.set(flag ? handler_1 : handler_2); | ||
</script> | ||
|
||
<button on:click={() => flag = !flag}>toggle</button> | ||
|
||
<p>{number}</p> | ||
|
||
<button on:click={handler_a}>handler_a</button> | ||
<button on:click={$handler_b}>handler_b</button> |