1- import { fireEvent as dtlFireEvent , getQueriesForElement , prettyDOM } from '@testing-library/dom'
1+ import {
2+ fireEvent as dtlFireEvent ,
3+ getQueriesForElement ,
4+ prettyDOM
5+ } from '@testing-library/dom'
26import { tick } from 'svelte'
37
48const containerCache = new Map ( )
59const componentCache = new Set ( )
610
7- const svleteComponentOptions = [ 'anchor' , 'props' , 'hydrate' , 'intro' ]
11+ const svelteComponentOptions = [
12+ 'anchor' ,
13+ 'props' ,
14+ 'hydrate' ,
15+ 'intro' ,
16+ 'context'
17+ ]
818
919const render = (
1020 Component ,
@@ -17,19 +27,21 @@ const render = (
1727 const ComponentConstructor = Component . default || Component
1828
1929 const checkProps = ( options ) => {
20- const isProps = ! Object . keys ( options ) . some ( option => svleteComponentOptions . includes ( option ) )
30+ const isProps = ! Object . keys ( options ) . some ( ( option ) =>
31+ svelteComponentOptions . includes ( option )
32+ )
2133
2234 // Check if any props and Svelte options were accidentally mixed.
2335 if ( ! isProps ) {
24- const unrecognizedOptions = Object
25- . keys ( options )
26- . filter ( option => ! svleteComponentOptions . includes ( option ) )
36+ const unrecognizedOptions = Object . keys ( options ) . filter (
37+ ( option ) => ! svelteComponentOptions . includes ( option )
38+ )
2739
2840 if ( unrecognizedOptions . length > 0 ) {
2941 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
42+ Unknown options were found [${ unrecognizedOptions } ]. This might happen if you've mixed
43+ passing in props with Svelte options into the render function. Valid Svelte options
44+ are [${ svelteComponentOptions } ]. You can either change the prop names, or pass in your
3345 props for that component via the \`props\` option.\n\n
3446 Eg: const { /** Results **/ } = render(MyComponent, { props: { /** props here **/ } })\n\n
3547 ` )
@@ -49,7 +61,9 @@ const render = (
4961 containerCache . set ( container , { target, component } )
5062 componentCache . add ( component )
5163
52- component . $$ . on_destroy . push ( ( ) => { componentCache . delete ( component ) } )
64+ component . $$ . on_destroy . push ( ( ) => {
65+ componentCache . delete ( component )
66+ } )
5367
5468 return {
5569 container,
@@ -67,7 +81,9 @@ const render = (
6781 containerCache . set ( container , { target, newComponent } )
6882 componentCache . add ( newComponent )
6983
70- newComponent . $$ . on_destroy . push ( ( ) => { componentCache . delete ( newComponent ) } )
84+ newComponent . $$ . on_destroy . push ( ( ) => {
85+ componentCache . delete ( newComponent )
86+ } )
7187 } ,
7288 unmount : ( ) => {
7389 if ( componentCache . has ( component ) ) component . $destroy ( )
@@ -76,12 +92,14 @@ const render = (
7692 }
7793}
7894
79- const cleanupAtContainer = container => {
95+ const cleanupAtContainer = ( container ) => {
8096 const { target, component } = containerCache . get ( container )
8197
8298 if ( componentCache . has ( component ) ) component . $destroy ( )
8399
84- if ( target . parentNode === document . body ) { document . body . removeChild ( target ) }
100+ if ( target . parentNode === document . body ) {
101+ document . body . removeChild ( target )
102+ }
85103
86104 containerCache . delete ( container )
87105}
@@ -116,6 +134,4 @@ Object.keys(dtlFireEvent).forEach((key) => {
116134
117135export * from '@testing-library/dom'
118136
119- export {
120- render , cleanup , fireEvent , act
121- }
137+ export { render , cleanup , fireEvent , act }
0 commit comments