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