Skip to content

Commit 40a7a82

Browse files
committed
add lifecycle test
1 parent e7a6db8 commit 40a7a82

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
const { page } = require('test-hmr/commands')
2+
3+
describe('lifecycle', () => {
4+
testHmr`
5+
# onMount
6+
7+
${function*() {
8+
for (const fn of ['mounted', 'unmounted']) {
9+
this[fn] = sinon.fake()
10+
yield page.exposeFunction(fn, this[fn])
11+
}
12+
}}
13+
14+
--- App.svelte ---
15+
16+
<script>
17+
import { onMount } from 'svelte'
18+
19+
onMount(() => {
20+
mounted()
21+
return () => {
22+
unmounted()
23+
}
24+
})
25+
</script>
26+
27+
::0 foo
28+
::1 bar
29+
::2 baz
30+
31+
* * *
32+
33+
::0::
34+
35+
foo
36+
37+
${function*() {
38+
expect(this.mounted).to.have.been.calledOnce
39+
expect(this.unmounted).to.not.have.been.called
40+
}}
41+
42+
::1::
43+
44+
bar
45+
46+
${function*() {
47+
expect(this.mounted).to.have.been.calledTwice
48+
expect(this.unmounted).to.have.been.calledOnce
49+
}}
50+
51+
::2::
52+
53+
baz
54+
55+
${function*() {
56+
expect(this.mounted).to.have.been.calledThrice
57+
expect(this.unmounted).to.have.been.calledTwice
58+
}}
59+
60+
`
61+
})

0 commit comments

Comments
 (0)