File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,12 @@ describe('render', () => {
5858 expect ( container ) . toMatchSnapshot ( )
5959 } )
6060
61+ test ( 'should throw error when mixing svelte component options and props' , ( ) => {
62+ expect ( ( ) => {
63+ stlRender ( Comp , { anchor : '' , name : 'World' } )
64+ } ) . toThrow ( / U n k n o w n o p t i o n s w e r e f o u n d / )
65+ } )
66+
6167 test ( 'should return a container object, which contains the DOM of the rendered component' , ( ) => {
6268 const { container } = render ( )
6369
Original file line number Diff line number Diff line change @@ -17,6 +17,23 @@ const render = (
1717 const ComponentConstructor = Component . default || Component
1818 const isProps = ! Object . keys ( options ) . some ( option => svleteComponentOptions . includes ( option ) )
1919
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+ ` )
34+ }
35+ }
36+
2037 const component = new ComponentConstructor ( {
2138 target,
2239 ...( isProps ? { props : options } : options )
You can’t perform that action at this time.
0 commit comments