File tree 1 file changed +8
-3
lines changed
1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -3,9 +3,10 @@ import {
3
3
getQueriesForElement ,
4
4
prettyDOM ,
5
5
} from '@testing-library/dom'
6
+ import { VERSION as SVELTE_VERSION } from 'svelte/compiler'
6
7
import * as Svelte from 'svelte'
7
8
8
- const IS_SVELTE_5 = typeof Svelte . createRoot === 'function'
9
+ const IS_SVELTE_5 = / ^ 5 \. / . test ( SVELTE_VERSION )
9
10
const targetCache = new Set ( )
10
11
const componentCache = new Set ( )
11
12
@@ -55,7 +56,7 @@ const render = (
55
56
options = { target, ...checkProps ( options ) }
56
57
57
58
const component = IS_SVELTE_5
58
- ? Svelte . createRoot ( ComponentConstructor , options )
59
+ ? Svelte . mount ( ComponentConstructor , options )
59
60
: new ComponentConstructor ( options )
60
61
61
62
componentCache . add ( component )
@@ -98,7 +99,11 @@ const cleanupComponent = (component) => {
98
99
const inCache = componentCache . delete ( component )
99
100
100
101
if ( inCache ) {
101
- component . $destroy ( )
102
+ if ( IS_SVELTE_5 ) {
103
+ Svelte . unmount ( component )
104
+ } else {
105
+ component . $destroy ( )
106
+ }
102
107
}
103
108
}
104
109
You can’t perform that action at this time.
0 commit comments