File tree Expand file tree Collapse file tree 1 file changed +61
-0
lines changed
packages/svelte-hmr-spec/test Expand file tree Collapse file tree 1 file changed +61
-0
lines changed Original file line number Diff line number Diff line change 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+ } )
You can’t perform that action at this time.
0 commit comments