1
+ import { VERSION as SVELTE_VERSION } from 'svelte/compiler'
1
2
import { beforeEach , describe , expect , test } from 'vitest'
2
3
3
4
import { act , render as stlRender } from '..'
@@ -11,13 +12,13 @@ describe('render', () => {
11
12
return stlRender ( Comp , {
12
13
target : document . body ,
13
14
props,
14
- ...additional
15
+ ...additional ,
15
16
} )
16
17
}
17
18
18
19
beforeEach ( ( ) => {
19
20
props = {
20
- name : 'World'
21
+ name : 'World' ,
21
22
}
22
23
} )
23
24
@@ -41,7 +42,9 @@ describe('render', () => {
41
42
} )
42
43
43
44
test ( 'change props with accessors' , async ( ) => {
44
- const { component, getByText } = render ( { accessors : true } )
45
+ const { component, getByText } = render (
46
+ SVELTE_VERSION < '5' ? { accessors : true } : { }
47
+ )
45
48
46
49
expect ( getByText ( 'Hello World!' ) ) . toBeInTheDocument ( )
47
50
@@ -59,23 +62,41 @@ describe('render', () => {
59
62
expect ( getByText ( 'Hello World!' ) ) . toBeInTheDocument ( )
60
63
} )
61
64
62
- test ( 'should accept svelte component options' , ( ) => {
63
- const target = document . createElement ( 'div' )
64
- const div = document . createElement ( 'div' )
65
- document . body . appendChild ( target )
66
- target . appendChild ( div )
67
- const { container } = stlRender ( Comp , {
68
- target,
69
- anchor : div ,
70
- props : { name : 'World' } ,
71
- context : new Map ( [ [ 'name' , 'context' ] ] )
72
- } )
73
- expect ( container ) . toMatchSnapshot ( )
74
- } )
65
+ test . runIf ( SVELTE_VERSION < '5' ) (
66
+ 'should accept svelte v4 component options' ,
67
+ ( ) => {
68
+ const target = document . createElement ( 'div' )
69
+ const div = document . createElement ( 'div' )
70
+ document . body . appendChild ( target )
71
+ target . appendChild ( div )
72
+ const { container } = stlRender ( Comp , {
73
+ target,
74
+ anchor : div ,
75
+ props : { name : 'World' } ,
76
+ context : new Map ( [ [ 'name' , 'context' ] ] ) ,
77
+ } )
78
+ expect ( container ) . toMatchSnapshot ( )
79
+ }
80
+ )
81
+
82
+ test . runIf ( SVELTE_VERSION >= '5' ) (
83
+ 'should accept svelte v5 component options' ,
84
+ ( ) => {
85
+ const target = document . createElement ( 'section' )
86
+ document . body . appendChild ( target )
87
+
88
+ const { container } = stlRender ( Comp , {
89
+ target,
90
+ props : { name : 'World' } ,
91
+ context : new Map ( [ [ 'name' , 'context' ] ] ) ,
92
+ } )
93
+ expect ( container ) . toMatchSnapshot ( )
94
+ }
95
+ )
75
96
76
97
test ( 'should throw error when mixing svelte component options and props' , ( ) => {
77
98
expect ( ( ) => {
78
- stlRender ( Comp , { anchor : '' , name : 'World' } )
99
+ stlRender ( Comp , { props : { } , name : 'World' } )
79
100
} ) . toThrow ( / U n k n o w n o p t i o n s w e r e f o u n d / )
80
101
} )
81
102
@@ -93,10 +114,8 @@ describe('render', () => {
93
114
94
115
test ( "accept the 'context' option" , ( ) => {
95
116
const { getByText } = stlRender ( Comp , {
96
- props : {
97
- name : 'Universe'
98
- } ,
99
- context : new Map ( [ [ 'name' , 'context' ] ] )
117
+ props : { name : 'Universe' } ,
118
+ context : new Map ( [ [ 'name' , 'context' ] ] ) ,
100
119
} )
101
120
102
121
expect ( getByText ( 'we have context' ) ) . toBeInTheDocument ( )
0 commit comments