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'
2
6
import { tick } from 'svelte'
3
7
4
8
const containerCache = new Map ( )
5
9
const componentCache = new Set ( )
6
10
7
- const svleteComponentOptions = [ 'anchor' , 'props' , 'hydrate' , 'intro' ]
11
+ const svelteComponentOptions = [
12
+ 'anchor' ,
13
+ 'props' ,
14
+ 'hydrate' ,
15
+ 'intro' ,
16
+ 'context'
17
+ ]
8
18
9
19
const render = (
10
20
Component ,
@@ -17,19 +27,21 @@ const render = (
17
27
const ComponentConstructor = Component . default || Component
18
28
19
29
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
+ )
21
33
22
34
// Check if any props and Svelte options were accidentally mixed.
23
35
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
+ )
27
39
28
40
if ( unrecognizedOptions . length > 0 ) {
29
41
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
33
45
props for that component via the \`props\` option.\n\n
34
46
Eg: const { /** Results **/ } = render(MyComponent, { props: { /** props here **/ } })\n\n
35
47
` )
@@ -49,7 +61,9 @@ const render = (
49
61
containerCache . set ( container , { target, component } )
50
62
componentCache . add ( component )
51
63
52
- component . $$ . on_destroy . push ( ( ) => { componentCache . delete ( component ) } )
64
+ component . $$ . on_destroy . push ( ( ) => {
65
+ componentCache . delete ( component )
66
+ } )
53
67
54
68
return {
55
69
container,
@@ -67,7 +81,9 @@ const render = (
67
81
containerCache . set ( container , { target, newComponent } )
68
82
componentCache . add ( newComponent )
69
83
70
- newComponent . $$ . on_destroy . push ( ( ) => { componentCache . delete ( newComponent ) } )
84
+ newComponent . $$ . on_destroy . push ( ( ) => {
85
+ componentCache . delete ( newComponent )
86
+ } )
71
87
} ,
72
88
unmount : ( ) => {
73
89
if ( componentCache . has ( component ) ) component . $destroy ( )
@@ -76,12 +92,14 @@ const render = (
76
92
}
77
93
}
78
94
79
- const cleanupAtContainer = container => {
95
+ const cleanupAtContainer = ( container ) => {
80
96
const { target, component } = containerCache . get ( container )
81
97
82
98
if ( componentCache . has ( component ) ) component . $destroy ( )
83
99
84
- if ( target . parentNode === document . body ) { document . body . removeChild ( target ) }
100
+ if ( target . parentNode === document . body ) {
101
+ document . body . removeChild ( target )
102
+ }
85
103
86
104
containerCache . delete ( container )
87
105
}
@@ -116,6 +134,4 @@ Object.keys(dtlFireEvent).forEach((key) => {
116
134
117
135
export * from '@testing-library/dom'
118
136
119
- export {
120
- render , cleanup , fireEvent , act
121
- }
137
+ export { render , cleanup , fireEvent , act }
0 commit comments