-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix dynamic event handler expression
- Loading branch information
Showing
3 changed files
with
34 additions
and
0 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
20 changes: 20 additions & 0 deletions
20
test/runtime/samples/event-handler-dynamic-expression/_config.js
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 @@ | ||
export default { | ||
html: `<button>bar</button>`, | ||
|
||
async test({ assert, component, target, window }) { | ||
const [button] = target.querySelectorAll( | ||
'button' | ||
); | ||
|
||
const event = new window.MouseEvent('click'); | ||
|
||
await button.dispatchEvent(event); | ||
assert.htmlEqual(target.innerHTML, `<button>foo</button>`); | ||
|
||
await button.dispatchEvent(event); | ||
assert.htmlEqual(target.innerHTML, `<button>bar</button>`); | ||
|
||
await button.dispatchEvent(event); | ||
assert.htmlEqual(target.innerHTML, `<button>foo</button>`); | ||
}, | ||
}; |
12 changes: 12 additions & 0 deletions
12
test/runtime/samples/event-handler-dynamic-expression/main.svelte
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,12 @@ | ||
<script> | ||
let name = 'bar'; | ||
function foo() { | ||
name = 'foo'; | ||
} | ||
function bar() { | ||
name = 'bar'; | ||
} | ||
</script> | ||
|
||
<button on:click={name === 'bar' ? foo : bar}>{name}</button> |