1
1
import { describe , expect , test , vi } from 'vitest'
2
+ import { VERSION as SVELTE_VERSION } from 'svelte/compiler'
2
3
3
4
import { act , render , screen } from '..'
4
5
import Mounter from './fixtures/Mounter.svelte'
@@ -7,27 +8,30 @@ const onMounted = vi.fn()
7
8
const onDestroyed = vi . fn ( )
8
9
const renderSubject = ( ) => render ( Mounter , { onMounted, onDestroyed } )
9
10
10
- describe ( 'mount and destroy' , ( ) => {
11
- test ( 'component is mounted' , async ( ) => {
12
- renderSubject ( )
11
+ describe . skipIf ( SVELTE_VERSION >= '5' && process . env . VITEST_ENV == 'happy-dom' ) (
12
+ 'mount and destroy' ,
13
+ ( ) => {
14
+ test ( 'component is mounted' , async ( ) => {
15
+ renderSubject ( )
13
16
14
- const content = screen . getByRole ( 'button' )
17
+ const content = screen . getByRole ( 'button' )
15
18
16
- expect ( content ) . toBeInTheDocument ( )
17
- await act ( )
18
- expect ( onMounted ) . toHaveBeenCalledOnce ( )
19
- } )
19
+ expect ( content ) . toBeInTheDocument ( )
20
+ await act ( )
21
+ expect ( onMounted ) . toHaveBeenCalledOnce ( )
22
+ } )
20
23
21
- test ( 'component is destroyed' , async ( ) => {
22
- const { unmount } = renderSubject ( )
24
+ test ( 'component is destroyed' , async ( ) => {
25
+ const { unmount } = renderSubject ( )
23
26
24
- await act ( )
25
- unmount ( )
27
+ await act ( )
28
+ unmount ( )
26
29
27
- const content = screen . queryByRole ( 'button' )
30
+ const content = screen . queryByRole ( 'button' )
28
31
29
- expect ( content ) . not . toBeInTheDocument ( )
30
- await act ( )
31
- expect ( onDestroyed ) . toHaveBeenCalledOnce ( )
32
- } )
33
- } )
32
+ expect ( content ) . not . toBeInTheDocument ( )
33
+ await act ( )
34
+ expect ( onDestroyed ) . toHaveBeenCalledOnce ( )
35
+ } )
36
+ }
37
+ )
0 commit comments