mirror of https://github.com/sveltejs/svelte
Allow any expression to pass data to an action. Added a test for a ternary statement and a string template. Fixes #1676pull/1679/head
parent
f38bdaaadf
commit
ba5ede599a
@ -0,0 +1,20 @@
|
||||
export default {
|
||||
data: {
|
||||
target: 'World!',
|
||||
display: true,
|
||||
},
|
||||
|
||||
html: `
|
||||
<h1></h1>
|
||||
`,
|
||||
|
||||
test ( assert, component, target, window ) {
|
||||
const header = target.querySelector( 'h1' );
|
||||
const eventClick = new window.MouseEvent( 'click' );
|
||||
|
||||
header.dispatchEvent( eventClick );
|
||||
assert.htmlEqual( target.innerHTML, `
|
||||
<h1>Hello World!</h1>
|
||||
` );
|
||||
}
|
||||
};
|
@ -0,0 +1,21 @@
|
||||
<h1 use:insert="display ? `Hello ${target}` : ''"></h1>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
actions: {
|
||||
insert(node, text) {
|
||||
|
||||
function onClick() {
|
||||
node.textContent = text;
|
||||
}
|
||||
node.addEventListener('click', onClick);
|
||||
|
||||
return {
|
||||
destroy() {
|
||||
node.removeEventListener('click', onClick);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
Loading…
Reference in new issue