1+ import { VERSION as SVELTE_VERSION } from 'svelte/compiler'
12import { beforeEach , describe , expect , test } from 'vitest'
23
34import { act , render as stlRender } from '..'
@@ -11,13 +12,13 @@ describe('render', () => {
1112 return stlRender ( Comp , {
1213 target : document . body ,
1314 props,
14- ...additional
15+ ...additional ,
1516 } )
1617 }
1718
1819 beforeEach ( ( ) => {
1920 props = {
20- name : 'World'
21+ name : 'World' ,
2122 }
2223 } )
2324
@@ -41,7 +42,9 @@ describe('render', () => {
4142 } )
4243
4344 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+ )
4548
4649 expect ( getByText ( 'Hello World!' ) ) . toBeInTheDocument ( )
4750
@@ -59,23 +62,41 @@ describe('render', () => {
5962 expect ( getByText ( 'Hello World!' ) ) . toBeInTheDocument ( )
6063 } )
6164
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+ )
7596
7697 test ( 'should throw error when mixing svelte component options and props' , ( ) => {
7798 expect ( ( ) => {
78- stlRender ( Comp , { anchor : '' , name : 'World' } )
99+ stlRender ( Comp , { props : { } , name : 'World' } )
79100 } ) . toThrow ( / U n k n o w n o p t i o n s w e r e f o u n d / )
80101 } )
81102
@@ -93,10 +114,8 @@ describe('render', () => {
93114
94115 test ( "accept the 'context' option" , ( ) => {
95116 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' ] ] ) ,
100119 } )
101120
102121 expect ( getByText ( 'we have context' ) ) . toBeInTheDocument ( )
0 commit comments