11import { describe , expect , test , vi } from 'vitest'
2+ import { VERSION as SVELTE_VERSION } from 'svelte/compiler'
23
34import { act , render , screen } from '..'
45import Mounter from './fixtures/Mounter.svelte'
@@ -7,27 +8,30 @@ const onMounted = vi.fn()
78const onDestroyed = vi . fn ( )
89const renderSubject = ( ) => render ( Mounter , { onMounted, onDestroyed } )
910
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 ( )
1316
14- const content = screen . getByRole ( 'button' )
17+ const content = screen . getByRole ( 'button' )
1518
16- expect ( content ) . toBeInTheDocument ( )
17- await act ( )
18- expect ( onMounted ) . toHaveBeenCalledOnce ( )
19- } )
19+ expect ( content ) . toBeInTheDocument ( )
20+ await act ( )
21+ expect ( onMounted ) . toHaveBeenCalledOnce ( )
22+ } )
2023
21- test ( 'component is destroyed' , async ( ) => {
22- const { unmount } = renderSubject ( )
24+ test ( 'component is destroyed' , async ( ) => {
25+ const { unmount } = renderSubject ( )
2326
24- await act ( )
25- unmount ( )
27+ await act ( )
28+ unmount ( )
2629
27- const content = screen . queryByRole ( 'button' )
30+ const content = screen . queryByRole ( 'button' )
2831
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