Skip to content

Commit 5c494f0

Browse files
committed
feat: add test for onDestroy call with transition nested component(sveltejs#5268)
1 parent 146e7a6 commit 5c494f0

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<script>
2+
import { onDestroy, createEventDispatcher } from 'svelte';
3+
const dispatch = createEventDispatcher();
4+
5+
onDestroy(() => dispatch('destroyed'));
6+
</script>
7+
8+
<div></div>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default {
2+
test({ assert, component, raf }) {
3+
component.visible = false;
4+
5+
raf.tick(50);
6+
assert.equal(component.destroyed, true);
7+
}
8+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<script>
2+
import Inner from './Inner.svelte';
3+
4+
export let visible = true, destroyed = false;
5+
6+
function foo(node) {
7+
return {
8+
duration: 100,
9+
tick: t => {
10+
node.foo = t;
11+
}
12+
};
13+
}
14+
15+
const onDestroy = () => {
16+
destroyed = true;
17+
};
18+
</script>
19+
20+
{#if visible}
21+
<div transition:foo>
22+
<Inner on:destroyed={onDestroy}/>
23+
</div>
24+
{/if}

0 commit comments

Comments
 (0)