@@ -15,28 +15,35 @@ const render = (
1515 target = target || container . appendChild ( document . createElement ( 'div' ) )
1616
1717 const ComponentConstructor = Component . default || Component
18- const isProps = ! Object . keys ( options ) . some ( option => svleteComponentOptions . includes ( option ) )
19-
20- // Check if any props and Svelte options were accidentally mixed.
21- if ( ! isProps ) {
22- const unrecognizedOptions = Object
23- . keys ( options )
24- . filter ( option => ! svleteComponentOptions . includes ( option ) )
25-
26- if ( unrecognizedOptions . length > 0 ) {
27- throw Error ( `
28- Unknown options were found [${ unrecognizedOptions } ]. This might happen if you've mixed
29- passing in props with Svelte options into the render function. Valid Svelte options
30- are [${ svleteComponentOptions } ]. You can either change the prop names, or pass in your
31- props for that component via the \`props\` option.\n\n
32- Eg: const { /** Results **/ } = render(MyComponent, { props: { /** props here **/ } })\n\n
33- ` )
18+
19+ const checkProps = ( options ) => {
20+ const isProps = ! Object . keys ( options ) . some ( option => svleteComponentOptions . includes ( option ) )
21+
22+ // Check if any props and Svelte options were accidentally mixed.
23+ if ( ! isProps ) {
24+ const unrecognizedOptions = Object
25+ . keys ( options )
26+ . filter ( option => ! svleteComponentOptions . includes ( option ) )
27+
28+ if ( unrecognizedOptions . length > 0 ) {
29+ throw Error ( `
30+ Unknown options were found [${ unrecognizedOptions } ]. This might happen if you've mixed
31+ passing in props with Svelte options into the render function. Valid Svelte options
32+ are [${ svleteComponentOptions } ]. You can either change the prop names, or pass in your
33+ props for that component via the \`props\` option.\n\n
34+ Eg: const { /** Results **/ } = render(MyComponent, { props: { /** props here **/ } })\n\n
35+ ` )
36+ }
37+
38+ return options
3439 }
40+
41+ return { props : options }
3542 }
3643
3744 const component = new ComponentConstructor ( {
3845 target,
39- ...( isProps ? { props : options } : options )
46+ ...checkProps ( options )
4047 } )
4148
4249 containerCache . set ( container , { target, component } )
@@ -53,8 +60,8 @@ const render = (
5360
5461 // eslint-disable-next-line no-new
5562 const newComponent = new ComponentConstructor ( {
56- ... options ,
57- target
63+ target ,
64+ ... checkProps ( options )
5865 } )
5966
6067 containerCache . set ( container , { target, newComponent } )
0 commit comments