1- import { getQueriesForElement , prettyDOM , Queries , BoundFunction } from "@testing-library/dom" ;
2- import { JSX } from "solid-js" ;
1+ import { getQueriesForElement , prettyDOM } from "@testing-library/dom" ;
32import { hydrate as solidHydrate , render as solidRender } from "solid-js/web" ;
4- import type { OptionsReceived } from "pretty-format" ;
3+
4+ import type { Ui , Result , Options , Ref } from "./types" ;
5+
6+ /**
7+ * Shim for the teardown function
8+ */
9+ declare var teardown : Function | undefined ;
510
611/* istanbul ignore next */
712if ( ! process . env . STL_SKIP_AUTO_CLEANUP ) {
813 if ( typeof afterEach === "function" ) {
914 afterEach ( async ( ) => {
1015 await cleanup ( ) ;
1116 } ) ;
12- // @ts -ignore
1317 } else if ( typeof teardown === "function" ) {
14- // @ts -ignore
1518 teardown ( async ( ) => {
1619 await cleanup ( ) ;
1720 } ) ;
1821 }
1922}
2023
21- const mountedContainers = new Set < { container : HTMLElement ; dispose : ( ) => void } > ( ) ;
24+ const mountedContainers = new Set < Ref > ( ) ;
25+
26+ function render ( ui : Ui , options : Options = { } ) : Result {
27+ let { container, baseElement = container , queries, hydrate = false } = options ;
2228
23- function render (
24- ui : ( ) => JSX . Element ,
25- {
26- container,
27- baseElement = container ,
28- queries,
29- hydrate = false
30- } : {
31- container ?: HTMLElement ;
32- baseElement ?: HTMLElement ;
33- queries ?: Queries ;
34- hydrate ?: boolean ;
35- } = { }
36- ) : {
37- container : HTMLElement ;
38- baseElement : HTMLElement ;
39- debug : (
40- baseElement ?: HTMLElement | HTMLElement [ ] ,
41- maxLength ?: number ,
42- options ?: OptionsReceived
43- ) => void ;
44- unmount : ( ) => void ;
45- } & { [ P in keyof Queries ] : BoundFunction < Queries [ P ] > } {
4629 if ( ! baseElement ) {
4730 // Default to document.body instead of documentElement to avoid output of potentially-large
4831 // head elements (such as JSS style blocks) in debug output.
@@ -65,16 +48,16 @@ function render(
6548 return {
6649 container,
6750 baseElement,
68- debug : ( el = baseElement , maxLength ?: number , options ?: OptionsReceived ) =>
51+ debug : ( el = baseElement , maxLength , options ) =>
6952 Array . isArray ( el )
7053 ? el . forEach ( e => console . log ( prettyDOM ( e , maxLength , options ) ) )
7154 : console . log ( prettyDOM ( el , maxLength , options ) ) ,
7255 unmount : dispose ,
7356 ...getQueriesForElement ( baseElement , queries )
74- } as any ;
57+ } as Result ;
7558}
7659
77- function cleanupAtContainer ( ref : { container : HTMLElement ; dispose : ( ) => void } ) {
60+ function cleanupAtContainer ( ref : Ref ) {
7861 const { container, dispose } = ref ;
7962 dispose ( ) ;
8063
0 commit comments