1- import {
2- configure as configureDTL ,
3- fireEvent as baseFireEvent ,
4- getConfig as getDTLConfig ,
5- getQueriesForElement ,
6- prettyDOM ,
7- } from '@testing-library/dom'
1+ import * as DomTestingLibrary from '@testing-library/dom'
82import * as Core from '@testing-library/svelte-core'
93import * as Svelte from 'svelte'
104
115/**
126 * Customize how Svelte renders the component.
137 *
8+ * @deprecated Use `import('@testing-library/svelte-core/types').ComponentOptions` instead
149 * @template {import('@testing-library/svelte-core/types').Component } C
1510 * @typedef {import('@testing-library/svelte-core/types').ComponentOptions<C> } SvelteComponentOptions
1611 */
1712
1813/**
1914 * Customize how Testing Library sets up the document and binds queries.
2015 *
21- * @template {import('@testing-library/dom').Queries } [Q=typeof import('@testing-library/dom').queries]
22- * @typedef {{
23- * baseElement?: HTMLElement
24- * queries?: Q
25- * }} RenderOptions
16+ * @template {DomTestingLibrary.Queries} [Q=typeof DomTestingLibrary.queries]
17+ * @typedef {import('@testing-library/svelte-core/types').SetupOptions & { queries?: Q } } RenderOptions
2618 */
2719
2820/**
2921 * The rendered component and bound testing functions.
3022 *
3123 * @template {import('@testing-library/svelte-core/types').Component } C
32- * @template {import(' @testing-library/dom') .Queries } [Q=typeof import('@testing-library/dom') .queries]
24+ * @template {DomTestingLibrary .Queries} [Q=typeof DomTestingLibrary .queries]
3325 *
3426 * @typedef {{
3527 * container: HTMLElement
@@ -39,18 +31,18 @@ import * as Svelte from 'svelte'
3931 * rerender: import('@testing-library/svelte-core/types').Rerender<C>
4032 * unmount: () => void
4133 * } & {
42- * [P in keyof Q]: import(' @testing -library/dom') .BoundFunction<Q[P]>
34+ * [P in keyof Q]: DomTestingLibrary .BoundFunction<Q[P]>
4335 * }} RenderResult
4436 */
4537
4638/**
4739 * Render a component into the document.
4840 *
4941 * @template {import('@testing-library/svelte-core/types').Component } C
50- * @template {import(' @testing-library/dom') .Queries } [Q=typeof import('@testing-library/dom') .queries]
42+ * @template {DomTestingLibrary .Queries} [Q=typeof DomTestingLibrary .queries]
5143 *
5244 * @param {import('@testing-library/svelte-core/types').ComponentImport<C> } Component - The component to render.
53- * @param {SvelteComponentOptions <C> } options - Customize how Svelte renders the component.
45+ * @param {import('@testing-library/svelte-core/types').ComponentOptions <C> } options - Customize how Svelte renders the component.
5446 * @param {RenderOptions<Q> } renderOptions - Customize how Testing Library sets up the document and binds queries.
5547 * @returns {RenderResult<C, Q> } The rendered component and bound testing functions.
5648 */
@@ -61,14 +53,19 @@ const render = (Component, options = {}, renderOptions = {}) => {
6153 renderOptions
6254 )
6355
56+ const queries = DomTestingLibrary . getQueriesForElement (
57+ baseElement ,
58+ renderOptions . queries
59+ )
60+
6461 return {
6562 baseElement,
6663 container,
6764 component,
6865 rerender,
6966 unmount,
70- debug : ( el = baseElement ) => console . log ( prettyDOM ( el ) ) ,
71- ...getQueriesForElement ( baseElement , renderOptions . queries ) ,
67+ debug : ( el = baseElement ) => console . log ( DomTestingLibrary . prettyDOM ( el ) ) ,
68+ ...queries ,
7269 }
7370}
7471
@@ -80,15 +77,15 @@ const render = (Component, options = {}, renderOptions = {}) => {
8077 * to flush changes to the DOM before proceeding.
8178 */
8279const setup = ( ) => {
83- const originalDTLConfig = getDTLConfig ( )
80+ const originalConfig = DomTestingLibrary . getConfig ( )
8481
85- configureDTL ( {
82+ DomTestingLibrary . configure ( {
8683 asyncWrapper : act ,
8784 eventWrapper : Svelte . flushSync ?? ( ( cb ) => cb ( ) ) ,
8885 } )
8986
9087 Core . addCleanupTask ( ( ) => {
91- configureDTL ( originalDTLConfig )
88+ DomTestingLibrary . configure ( originalConfig )
9289 } )
9390}
9491
@@ -101,7 +98,7 @@ const cleanup = () => {
10198 * Call a function and wait for Svelte to flush pending changes.
10299 *
103100 * @template T
104- * @param {(( ) => Promise<T>) | () => T } [fn] - A function, which may be `async`, to call before flushing updates.
101+ * @param {() => Promise<T> | T } [fn] - A function, which may be `async`, to call before flushing updates.
105102 * @returns {Promise<T> }
106103 */
107104const act = async ( fn ) => {
@@ -114,12 +111,12 @@ const act = async (fn) => {
114111}
115112
116113/**
117- * @typedef {(...args: Parameters<import('@testing-library/dom') .FireFunction>) => Promise<ReturnType<import('@testing-library/dom') .FireFunction>> } FireFunction
114+ * @typedef {(...args: Parameters<DomTestingLibrary .FireFunction>) => Promise<ReturnType<DomTestingLibrary .FireFunction>> } FireFunction
118115 */
119116
120117/**
121118 * @typedef {{
122- * [K in import(' @testing -library/dom') .EventType]: (...args: Parameters<import('@testing-library/dom') .FireObject[K]>) => Promise<ReturnType<import('@testing-library/dom') .FireObject[K]>>
119+ * [K in DomTestingLibrary .EventType]: (...args: Parameters<DomTestingLibrary .FireObject[K]>) => Promise<ReturnType<DomTestingLibrary .FireObject[K]>>
123120 * }} FireObject
124121 */
125122
@@ -131,11 +128,14 @@ const act = async (fn) => {
131128 *
132129 * @type {FireFunction & FireObject }
133130 */
134- const fireEvent = async ( ...args ) => act ( ( ) => baseFireEvent ( ...args ) )
131+ const fireEvent = async ( ...args ) => {
132+ return act ( ( ) => DomTestingLibrary . fireEvent ( ...args ) )
133+ }
135134
136- for ( const [ key , baseEvent ] of Object . entries ( baseFireEvent ) ) {
135+ for ( const [ key , baseEvent ] of Object . entries ( DomTestingLibrary . fireEvent ) ) {
137136 fireEvent [ key ] = async ( ...args ) => act ( ( ) => baseEvent ( ...args ) )
138137}
139138
139+ export * from '@testing-library/dom'
140140export { UnknownSvelteOptionsError } from '@testing-library/svelte-core'
141141export { act , cleanup , fireEvent , render , setup }
0 commit comments