mirror of https://github.com/sveltejs/svelte
parent
b99ee7d5d1
commit
9a154e0d3b
@ -0,0 +1,23 @@
|
|||||||
|
export default {
|
||||||
|
html: `<div>bind</div>`,
|
||||||
|
|
||||||
|
async test({ assert, component, target }) {
|
||||||
|
assert.equal(component.ref, target.querySelector('div'));
|
||||||
|
assert.equal(component.hooks[0], 'Before');
|
||||||
|
assert.equal(component.hooks.pop(), 'After');
|
||||||
|
|
||||||
|
while (component.hooks.length) component.hooks.pop();
|
||||||
|
|
||||||
|
component.bind = false;
|
||||||
|
assert.equal(component.ref, null);
|
||||||
|
assert.equal(component.hooks[0], 'Before');
|
||||||
|
assert.equal(component.hooks.pop(), 'After');
|
||||||
|
|
||||||
|
while (component.hooks.length) component.hooks.pop();
|
||||||
|
|
||||||
|
component.bind = true;
|
||||||
|
assert.equal(component.ref, target.querySelector('div'));
|
||||||
|
assert.equal(component.hooks[0], 'Before');
|
||||||
|
assert.equal(component.hooks.pop(), 'After');
|
||||||
|
}
|
||||||
|
};
|
@ -0,0 +1,15 @@
|
|||||||
|
<script>
|
||||||
|
// adapted from https://svelte.dev/repl/8a96e6e545244bff9fd0125b152d6840?version=3.6.9
|
||||||
|
import { afterUpdate, beforeUpdate, onMount } from 'svelte';
|
||||||
|
|
||||||
|
export let ref = null, bind = true, hooks = [];
|
||||||
|
|
||||||
|
// using push to not make hooks reactive
|
||||||
|
beforeUpdate(() => hooks.push('Before'))
|
||||||
|
afterUpdate(() => hooks.push('After'))
|
||||||
|
onMount(() => hooks.push('Mount'))
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if bind}
|
||||||
|
<div bind:this={ref}>bind</div>
|
||||||
|
{/if}
|
Loading…
Reference in new issue