1
1
import { afterEach , beforeEach , describe , expect , test , vi } from 'vitest'
2
2
3
- import Comp from './fixtures/Comp.svelte'
4
3
import { IS_SVELTE_5 } from './utils.js'
5
4
6
5
const importSvelteTestingLibrary = async ( ) =>
@@ -24,12 +23,14 @@ describe('auto-cleanup', () => {
24
23
25
24
test ( 'calls afterEach with cleanup if globally defined' , async ( ) => {
26
25
const { render } = await importSvelteTestingLibrary ( )
26
+ const { default : Comp } = await import ( './fixtures/Comp.svelte' )
27
+
27
28
render ( Comp , { props : { name : 'world' } } )
28
29
29
30
expect ( globalAfterEach ) . toHaveBeenCalledTimes ( 1 )
30
31
expect ( globalAfterEach ) . toHaveBeenLastCalledWith ( expect . any ( Function ) )
31
32
32
- await afterEach . mock . lastCall [ 0 ] ( )
33
+ await globalAfterEach . mock . lastCall [ 0 ] ( )
33
34
34
35
expect ( document . body ) . toBeEmptyDOMElement ( )
35
36
} )
@@ -38,13 +39,17 @@ describe('auto-cleanup', () => {
38
39
process . env . STL_SKIP_AUTO_CLEANUP = 'true'
39
40
40
41
const { render } = await importSvelteTestingLibrary ( )
42
+ const { default : Comp } = await import ( './fixtures/Comp.svelte' )
43
+
41
44
render ( Comp , { props : { name : 'world' } } )
42
45
43
46
expect ( globalAfterEach ) . toHaveBeenCalledTimes ( 0 )
44
47
} )
45
48
46
49
test ( 'does not call afterEach if you import from `pure`' , async ( ) => {
47
50
const { render } = await importSvelteTestingLibraryPure ( )
51
+ const { default : Comp } = await import ( './fixtures/Comp.svelte' )
52
+
48
53
render ( Comp , { props : { name : 'world' } } )
49
54
50
55
expect ( globalAfterEach ) . toHaveBeenCalledTimes ( 0 )
0 commit comments