@testing-library/svelte 5.3.0-next.1 → 5.3.0-next.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -2
- package/dist/pure.d.ts +19 -20
- package/dist/pure.d.ts.map +1 -1
- package/package.json +6 -2
- package/src/index.js +1 -12
- package/src/pure.js +26 -26
package/dist/index.d.ts
CHANGED
package/dist/pure.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * from "@testing-library/dom";
|
|
1
2
|
export { UnknownSvelteOptionsError } from "@testing-library/svelte-core";
|
|
2
3
|
/**
|
|
3
4
|
* Customize how Svelte renders the component.
|
|
@@ -6,39 +7,38 @@ export type SvelteComponentOptions<C extends import("@testing-library/svelte-cor
|
|
|
6
7
|
/**
|
|
7
8
|
* Customize how Testing Library sets up the document and binds queries.
|
|
8
9
|
*/
|
|
9
|
-
export type RenderOptions<Q extends
|
|
10
|
-
baseElement?: HTMLElement;
|
|
10
|
+
export type RenderOptions<Q extends DomTestingLibrary.Queries = typeof DomTestingLibrary.queries> = import("@testing-library/svelte-core/types").SetupOptions & {
|
|
11
11
|
queries?: Q;
|
|
12
12
|
};
|
|
13
13
|
/**
|
|
14
14
|
* The rendered component and bound testing functions.
|
|
15
15
|
*/
|
|
16
|
-
export type RenderResult<C extends import("@testing-library/svelte-core/types").Component, Q extends
|
|
16
|
+
export type RenderResult<C extends import("@testing-library/svelte-core/types").Component, Q extends DomTestingLibrary.Queries = typeof DomTestingLibrary.queries> = {
|
|
17
17
|
container: HTMLElement;
|
|
18
18
|
baseElement: HTMLElement;
|
|
19
19
|
component: import("@testing-library/svelte-core/types").Exports<C>;
|
|
20
20
|
debug: (el?: HTMLElement | DocumentFragment) => void;
|
|
21
21
|
rerender: import("@testing-library/svelte-core/types").Rerender<C>;
|
|
22
22
|
unmount: () => void;
|
|
23
|
-
} & { [P in keyof Q]:
|
|
24
|
-
export type FireFunction = (...args: Parameters<
|
|
25
|
-
export type FireObject = { [K in
|
|
23
|
+
} & { [P in keyof Q]: DomTestingLibrary.BoundFunction<Q[P]>; };
|
|
24
|
+
export type FireFunction = (...args: Parameters<DomTestingLibrary.FireFunction>) => Promise<ReturnType<DomTestingLibrary.FireFunction>>;
|
|
25
|
+
export type FireObject = { [K in DomTestingLibrary.EventType]: (...args: Parameters<DomTestingLibrary.FireObject[K]>) => Promise<ReturnType<DomTestingLibrary.FireObject[K]>>; };
|
|
26
26
|
/**
|
|
27
27
|
* Call a function and wait for Svelte to flush pending changes.
|
|
28
28
|
*
|
|
29
29
|
* @template T
|
|
30
|
-
* @param {(
|
|
30
|
+
* @param {() => Promise<T> | T} [fn] - A function, which may be `async`, to call before flushing updates.
|
|
31
31
|
* @returns {Promise<T>}
|
|
32
32
|
*/
|
|
33
|
-
export function act<T>(fn?: (
|
|
33
|
+
export function act<T>(fn?: () => Promise<T> | T): Promise<T>;
|
|
34
34
|
/** Unmount components, remove elements added to `<body>`, and reset `@testing-library/dom`. */
|
|
35
35
|
export function cleanup(): void;
|
|
36
36
|
/**
|
|
37
|
-
* @typedef {(...args: Parameters<
|
|
37
|
+
* @typedef {(...args: Parameters<DomTestingLibrary.FireFunction>) => Promise<ReturnType<DomTestingLibrary.FireFunction>>} FireFunction
|
|
38
38
|
*/
|
|
39
39
|
/**
|
|
40
40
|
* @typedef {{
|
|
41
|
-
* [K in
|
|
41
|
+
* [K in DomTestingLibrary.EventType]: (...args: Parameters<DomTestingLibrary.FireObject[K]>) => Promise<ReturnType<DomTestingLibrary.FireObject[K]>>
|
|
42
42
|
* }} FireObject
|
|
43
43
|
*/
|
|
44
44
|
/**
|
|
@@ -53,23 +53,21 @@ export const fireEvent: FireFunction & FireObject;
|
|
|
53
53
|
/**
|
|
54
54
|
* Customize how Svelte renders the component.
|
|
55
55
|
*
|
|
56
|
+
* @deprecated Use `import('@testing-library/svelte-core/types').ComponentOptions` instead
|
|
56
57
|
* @template {import('@testing-library/svelte-core/types').Component} C
|
|
57
58
|
* @typedef {import('@testing-library/svelte-core/types').ComponentOptions<C>} SvelteComponentOptions
|
|
58
59
|
*/
|
|
59
60
|
/**
|
|
60
61
|
* Customize how Testing Library sets up the document and binds queries.
|
|
61
62
|
*
|
|
62
|
-
* @template {
|
|
63
|
-
* @typedef {{
|
|
64
|
-
* baseElement?: HTMLElement
|
|
65
|
-
* queries?: Q
|
|
66
|
-
* }} RenderOptions
|
|
63
|
+
* @template {DomTestingLibrary.Queries} [Q=typeof DomTestingLibrary.queries]
|
|
64
|
+
* @typedef {import('@testing-library/svelte-core/types').SetupOptions & { queries?: Q }} RenderOptions
|
|
67
65
|
*/
|
|
68
66
|
/**
|
|
69
67
|
* The rendered component and bound testing functions.
|
|
70
68
|
*
|
|
71
69
|
* @template {import('@testing-library/svelte-core/types').Component} C
|
|
72
|
-
* @template {
|
|
70
|
+
* @template {DomTestingLibrary.Queries} [Q=typeof DomTestingLibrary.queries]
|
|
73
71
|
*
|
|
74
72
|
* @typedef {{
|
|
75
73
|
* container: HTMLElement
|
|
@@ -79,21 +77,21 @@ export const fireEvent: FireFunction & FireObject;
|
|
|
79
77
|
* rerender: import('@testing-library/svelte-core/types').Rerender<C>
|
|
80
78
|
* unmount: () => void
|
|
81
79
|
* } & {
|
|
82
|
-
* [P in keyof Q]:
|
|
80
|
+
* [P in keyof Q]: DomTestingLibrary.BoundFunction<Q[P]>
|
|
83
81
|
* }} RenderResult
|
|
84
82
|
*/
|
|
85
83
|
/**
|
|
86
84
|
* Render a component into the document.
|
|
87
85
|
*
|
|
88
86
|
* @template {import('@testing-library/svelte-core/types').Component} C
|
|
89
|
-
* @template {
|
|
87
|
+
* @template {DomTestingLibrary.Queries} [Q=typeof DomTestingLibrary.queries]
|
|
90
88
|
*
|
|
91
89
|
* @param {import('@testing-library/svelte-core/types').ComponentImport<C>} Component - The component to render.
|
|
92
|
-
* @param {
|
|
90
|
+
* @param {import('@testing-library/svelte-core/types').ComponentOptions<C>} options - Customize how Svelte renders the component.
|
|
93
91
|
* @param {RenderOptions<Q>} renderOptions - Customize how Testing Library sets up the document and binds queries.
|
|
94
92
|
* @returns {RenderResult<C, Q>} The rendered component and bound testing functions.
|
|
95
93
|
*/
|
|
96
|
-
export function render<C extends import("@testing-library/svelte-core/types").Component, Q extends
|
|
94
|
+
export function render<C extends import("@testing-library/svelte-core/types").Component, Q extends DomTestingLibrary.Queries = typeof DomTestingLibrary.queries>(Component: import("@testing-library/svelte-core/types").ComponentImport<C>, options?: import("@testing-library/svelte-core/types").ComponentOptions<C>, renderOptions?: RenderOptions<Q>): RenderResult<C, Q>;
|
|
97
95
|
/**
|
|
98
96
|
* Configure `@testing-library/dom` for usage with Svelte.
|
|
99
97
|
*
|
|
@@ -102,4 +100,5 @@ export function render<C extends import("@testing-library/svelte-core/types").Co
|
|
|
102
100
|
* to flush changes to the DOM before proceeding.
|
|
103
101
|
*/
|
|
104
102
|
export function setup(): void;
|
|
103
|
+
import * as DomTestingLibrary from '@testing-library/dom';
|
|
105
104
|
//# sourceMappingURL=pure.d.ts.map
|
package/dist/pure.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pure.d.ts","sourceRoot":"","sources":["../src/pure.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pure.d.ts","sourceRoot":"","sources":["../src/pure.js"],"names":[],"mappings":";;;;;mCAQsE,CAAC,SAA1D,OAAQ,oCAAoC,EAAE,SAAU,IACxD,OAAO,oCAAoC,EAAE,gBAAgB,CAAC,CAAC,CAAC;;;;0BAMnC,CAAC,SAA7B,iBAAiB,CAAC,OAAQ,uCAC3B,OAAO,oCAAoC,EAAE,YAAY,GAAG;IAAE,OAAO,CAAC,EAAE,CAAC,CAAA;CAAE;;;;yBAMlB,CAAC,SAA1D,OAAQ,oCAAoC,EAAE,SAAU,EAC3B,CAAC,SAA7B,iBAAiB,CAAC,OAAQ,uCAE3B;IACR,SAAS,EAAE,WAAW,CAAA;IACtB,WAAW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oC,EAAE,gBAAgB,CAAC,CAAC,CAAC,kBAChE,aAAa,CAAC,CAAC,CAAC,GACd,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAuB9B;AAED;;;;;;GAMG;AACH,8BAWC;mCAzFkC,sBAAsB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@testing-library/svelte",
|
|
3
|
-
"version": "5.3.0-next.
|
|
3
|
+
"version": "5.3.0-next.3",
|
|
4
4
|
"description": "Simple and complete Svelte testing utilities that encourage good testing practices.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -8,6 +8,10 @@
|
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"default": "./src/index.js"
|
|
10
10
|
},
|
|
11
|
+
"./pure": {
|
|
12
|
+
"types": "./dist/pure.d.ts",
|
|
13
|
+
"default": "./src/pure.js"
|
|
14
|
+
},
|
|
11
15
|
"./svelte5": {
|
|
12
16
|
"types": "./dist/index.d.ts",
|
|
13
17
|
"default": "./src/index.js"
|
|
@@ -67,7 +71,7 @@
|
|
|
67
71
|
},
|
|
68
72
|
"dependencies": {
|
|
69
73
|
"@testing-library/dom": "9.x.x || 10.x.x",
|
|
70
|
-
"@testing-library/svelte-core": "1.0.0-next.
|
|
74
|
+
"@testing-library/svelte-core": "1.0.0-next.5"
|
|
71
75
|
},
|
|
72
76
|
"publishConfig": {
|
|
73
77
|
"access": "public",
|
package/src/index.js
CHANGED
|
@@ -19,15 +19,4 @@ if (typeof process !== 'undefined' && !process.env.STL_SKIP_AUTO_CLEANUP) {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
export * from '@testing-library/dom'
|
|
24
|
-
|
|
25
|
-
// export svelte-specific functions and custom `fireEvent`
|
|
26
|
-
export {
|
|
27
|
-
act,
|
|
28
|
-
cleanup,
|
|
29
|
-
fireEvent,
|
|
30
|
-
render,
|
|
31
|
-
setup,
|
|
32
|
-
UnknownSvelteOptionsError,
|
|
33
|
-
} from './pure.js'
|
|
22
|
+
export * from './pure.js'
|
package/src/pure.js
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
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'
|
|
8
2
|
import * as Core from '@testing-library/svelte-core'
|
|
9
3
|
import * as Svelte from 'svelte'
|
|
10
4
|
|
|
11
5
|
/**
|
|
12
6
|
* Customize how Svelte renders the component.
|
|
13
7
|
*
|
|
8
|
+
* @deprecated Use `import('@testing-library/svelte-core/types').ComponentOptions` instead
|
|
14
9
|
* @template {import('@testing-library/svelte-core/types').Component} C
|
|
15
10
|
* @typedef {import('@testing-library/svelte-core/types').ComponentOptions<C>} SvelteComponentOptions
|
|
16
11
|
*/
|
|
@@ -18,18 +13,15 @@ import * as Svelte from 'svelte'
|
|
|
18
13
|
/**
|
|
19
14
|
* Customize how Testing Library sets up the document and binds queries.
|
|
20
15
|
*
|
|
21
|
-
* @template {
|
|
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
|
|
26
18
|
*/
|
|
27
19
|
|
|
28
20
|
/**
|
|
29
21
|
* The rendered component and bound testing functions.
|
|
30
22
|
*
|
|
31
23
|
* @template {import('@testing-library/svelte-core/types').Component} C
|
|
32
|
-
* @template {
|
|
24
|
+
* @template {DomTestingLibrary.Queries} [Q=typeof DomTestingLibrary.queries]
|
|
33
25
|
*
|
|
34
26
|
* @typedef {{
|
|
35
27
|
* container: HTMLElement
|
|
@@ -39,7 +31,7 @@ import * as Svelte from 'svelte'
|
|
|
39
31
|
* rerender: import('@testing-library/svelte-core/types').Rerender<C>
|
|
40
32
|
* unmount: () => void
|
|
41
33
|
* } & {
|
|
42
|
-
* [P in keyof Q]:
|
|
34
|
+
* [P in keyof Q]: DomTestingLibrary.BoundFunction<Q[P]>
|
|
43
35
|
* }} RenderResult
|
|
44
36
|
*/
|
|
45
37
|
|
|
@@ -47,10 +39,10 @@ import * as Svelte from 'svelte'
|
|
|
47
39
|
* Render a component into the document.
|
|
48
40
|
*
|
|
49
41
|
* @template {import('@testing-library/svelte-core/types').Component} C
|
|
50
|
-
* @template {
|
|
42
|
+
* @template {DomTestingLibrary.Queries} [Q=typeof DomTestingLibrary.queries]
|
|
51
43
|
*
|
|
52
44
|
* @param {import('@testing-library/svelte-core/types').ComponentImport<C>} Component - The component to render.
|
|
53
|
-
* @param {
|
|
45
|
+
* @param {import('@testing-library/svelte-core/types').ComponentOptions<C>} options - Customize how Svelte renders the component.
|
|
54
46
|
* @param {RenderOptions<Q>} renderOptions - Customize how Testing Library sets up the document and binds queries.
|
|
55
47
|
* @returns {RenderResult<C, Q>} The rendered component and bound testing functions.
|
|
56
48
|
*/
|
|
@@ -61,14 +53,19 @@ const render = (Component, options = {}, renderOptions = {}) => {
|
|
|
61
53
|
renderOptions
|
|
62
54
|
)
|
|
63
55
|
|
|
56
|
+
const queries = DomTestingLibrary.getQueriesForElement(
|
|
57
|
+
baseElement,
|
|
58
|
+
renderOptions.queries
|
|
59
|
+
)
|
|
60
|
+
|
|
64
61
|
return {
|
|
65
62
|
baseElement,
|
|
66
63
|
container,
|
|
67
64
|
component,
|
|
68
65
|
rerender,
|
|
69
66
|
unmount,
|
|
70
|
-
debug: (el = baseElement) => console.log(prettyDOM(el)),
|
|
71
|
-
...
|
|
67
|
+
debug: (el = baseElement) => console.log(DomTestingLibrary.prettyDOM(el)),
|
|
68
|
+
...queries,
|
|
72
69
|
}
|
|
73
70
|
}
|
|
74
71
|
|
|
@@ -80,15 +77,15 @@ const render = (Component, options = {}, renderOptions = {}) => {
|
|
|
80
77
|
* to flush changes to the DOM before proceeding.
|
|
81
78
|
*/
|
|
82
79
|
const setup = () => {
|
|
83
|
-
const
|
|
80
|
+
const originalConfig = DomTestingLibrary.getConfig()
|
|
84
81
|
|
|
85
|
-
|
|
82
|
+
DomTestingLibrary.configure({
|
|
86
83
|
asyncWrapper: act,
|
|
87
84
|
eventWrapper: Svelte.flushSync ?? ((cb) => cb()),
|
|
88
85
|
})
|
|
89
86
|
|
|
90
87
|
Core.addCleanupTask(() => {
|
|
91
|
-
|
|
88
|
+
DomTestingLibrary.configure(originalConfig)
|
|
92
89
|
})
|
|
93
90
|
}
|
|
94
91
|
|
|
@@ -101,7 +98,7 @@ const cleanup = () => {
|
|
|
101
98
|
* Call a function and wait for Svelte to flush pending changes.
|
|
102
99
|
*
|
|
103
100
|
* @template T
|
|
104
|
-
* @param {(
|
|
101
|
+
* @param {() => Promise<T> | T} [fn] - A function, which may be `async`, to call before flushing updates.
|
|
105
102
|
* @returns {Promise<T>}
|
|
106
103
|
*/
|
|
107
104
|
const act = async (fn) => {
|
|
@@ -114,12 +111,12 @@ const act = async (fn) => {
|
|
|
114
111
|
}
|
|
115
112
|
|
|
116
113
|
/**
|
|
117
|
-
* @typedef {(...args: Parameters<
|
|
114
|
+
* @typedef {(...args: Parameters<DomTestingLibrary.FireFunction>) => Promise<ReturnType<DomTestingLibrary.FireFunction>>} FireFunction
|
|
118
115
|
*/
|
|
119
116
|
|
|
120
117
|
/**
|
|
121
118
|
* @typedef {{
|
|
122
|
-
* [K in
|
|
119
|
+
* [K in DomTestingLibrary.EventType]: (...args: Parameters<DomTestingLibrary.FireObject[K]>) => Promise<ReturnType<DomTestingLibrary.FireObject[K]>>
|
|
123
120
|
* }} FireObject
|
|
124
121
|
*/
|
|
125
122
|
|
|
@@ -131,11 +128,14 @@ const act = async (fn) => {
|
|
|
131
128
|
*
|
|
132
129
|
* @type {FireFunction & FireObject}
|
|
133
130
|
*/
|
|
134
|
-
const fireEvent = async (...args) =>
|
|
131
|
+
const fireEvent = async (...args) => {
|
|
132
|
+
return act(() => DomTestingLibrary.fireEvent(...args))
|
|
133
|
+
}
|
|
135
134
|
|
|
136
|
-
for (const [key, baseEvent] of Object.entries(
|
|
135
|
+
for (const [key, baseEvent] of Object.entries(DomTestingLibrary.fireEvent)) {
|
|
137
136
|
fireEvent[key] = async (...args) => act(() => baseEvent(...args))
|
|
138
137
|
}
|
|
139
138
|
|
|
139
|
+
export * from '@testing-library/dom'
|
|
140
140
|
export { UnknownSvelteOptionsError } from '@testing-library/svelte-core'
|
|
141
141
|
export { act, cleanup, fireEvent, render, setup }
|