@testing-library/svelte 5.2.6 → 5.2.8
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/README.md +34 -0
- package/package.json +31 -35
- package/src/component-types.d.ts +8 -8
- package/src/core/index.js +3 -11
- package/src/index.js +16 -9
- package/src/pure.js +53 -23
- package/src/vite.js +7 -5
- package/src/vitest.js +9 -5
- package/types/component-types.d.ts +8 -8
- package/types/core/index.d.ts +1 -2
- package/types/core/index.d.ts.map +1 -1
- package/types/core/validate-options.d.ts.map +1 -1
- package/types/pure.d.ts +13 -4
- package/types/pure.d.ts.map +1 -1
package/README.md
CHANGED
|
@@ -70,6 +70,7 @@
|
|
|
70
70
|
- [This Solution](#this-solution)
|
|
71
71
|
- [Installation](#installation)
|
|
72
72
|
- [Setup](#setup)
|
|
73
|
+
- [Auto-cleanup](#auto-cleanup)
|
|
73
74
|
- [Docs](#docs)
|
|
74
75
|
- [Issues](#issues)
|
|
75
76
|
- [🐛 Bugs](#-bugs)
|
|
@@ -140,6 +141,39 @@ test runners like Jest.
|
|
|
140
141
|
[vitest]: https://vitest.dev/
|
|
141
142
|
[setup docs]: https://testing-library.com/docs/svelte-testing-library/setup
|
|
142
143
|
|
|
144
|
+
### Auto-cleanup
|
|
145
|
+
|
|
146
|
+
In Vitest (via the `svelteTesting` plugin) and Jest (via the `beforeEach` and `afterEach` globals),
|
|
147
|
+
this library will automatically setup and cleanup the test environment before and after each test.
|
|
148
|
+
|
|
149
|
+
To do your own cleanup, or if you're using another framework, call the `setup` and `cleanup` functions yourself:
|
|
150
|
+
|
|
151
|
+
```js
|
|
152
|
+
import { cleanup, render, setup } from '@testing-library/svelte'
|
|
153
|
+
|
|
154
|
+
// before
|
|
155
|
+
setup()
|
|
156
|
+
|
|
157
|
+
// test
|
|
158
|
+
render(/* ... */)
|
|
159
|
+
|
|
160
|
+
// after
|
|
161
|
+
cleanup()
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
To disable auto-cleanup in Vitest, set the `autoCleanup` option of the plugin to false:
|
|
165
|
+
|
|
166
|
+
```js
|
|
167
|
+
svelteTesting({ autoCleanup: false })
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
To disable auto-cleanup in Jest and other frameworks with global test hooks,
|
|
171
|
+
set the `STL_SKIP_AUTO_CLEANUP` environment variable:
|
|
172
|
+
|
|
173
|
+
```shell
|
|
174
|
+
STL_SKIP_AUTO_CLEANUP=1 jest
|
|
175
|
+
```
|
|
176
|
+
|
|
143
177
|
## Docs
|
|
144
178
|
|
|
145
179
|
See the [**docs**][stl-docs] over at the Testing Library website.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@testing-library/svelte",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.8",
|
|
4
4
|
"description": "Simple and complete Svelte testing utilities that encourage good testing practices.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -49,21 +49,15 @@
|
|
|
49
49
|
],
|
|
50
50
|
"files": [
|
|
51
51
|
"src",
|
|
52
|
-
"types"
|
|
53
|
-
"!__tests__"
|
|
52
|
+
"types"
|
|
54
53
|
],
|
|
55
54
|
"scripts": {
|
|
56
55
|
"all": "npm-run-all contributors:generate toc format types build test:vitest:* test:jest",
|
|
56
|
+
"all:legacy": "npm-run-all types:legacy test:vitest:* test:jest",
|
|
57
57
|
"toc": "doctoc README.md",
|
|
58
58
|
"lint": "prettier . --check && eslint .",
|
|
59
|
-
"lint:delta": "npm-run-all -p prettier:delta eslint:delta",
|
|
60
|
-
"prettier:delta": "prettier --check `./scripts/changed-files`",
|
|
61
|
-
"eslint:delta": "eslint `./scripts/changed-files`",
|
|
62
59
|
"format": "prettier . --write && eslint . --fix",
|
|
63
|
-
"
|
|
64
|
-
"format:prettier:delta": "prettier --write `./scripts/changed-files`",
|
|
65
|
-
"format:eslint:delta": "eslint --fix `./scripts/changed-files`",
|
|
66
|
-
"setup": "npm install && npm run all",
|
|
60
|
+
"setup": "npm run install:5 && npm run all",
|
|
67
61
|
"test": "vitest run --coverage",
|
|
68
62
|
"test:watch": "vitest",
|
|
69
63
|
"test:vitest:jsdom": "vitest run --coverage --environment jsdom",
|
|
@@ -71,7 +65,6 @@
|
|
|
71
65
|
"test:jest": "npx --node-options=\"--experimental-vm-modules --no-warnings\" jest --coverage",
|
|
72
66
|
"types": "svelte-check",
|
|
73
67
|
"types:legacy": "svelte-check --tsconfig tsconfig.legacy.json",
|
|
74
|
-
"validate": "npm-run-all test:vitest:* test:jest types build",
|
|
75
68
|
"build": "tsc -p tsconfig.build.json && cp src/component-types.d.ts types",
|
|
76
69
|
"contributors:add": "all-contributors add",
|
|
77
70
|
"contributors:generate": "all-contributors generate",
|
|
@@ -94,39 +87,42 @@
|
|
|
94
87
|
}
|
|
95
88
|
},
|
|
96
89
|
"dependencies": {
|
|
97
|
-
"@testing-library/dom": "
|
|
90
|
+
"@testing-library/dom": "9.x.x || 10.x.x"
|
|
98
91
|
},
|
|
99
92
|
"devDependencies": {
|
|
93
|
+
"@eslint/js": "^9.26.0",
|
|
100
94
|
"@jest/globals": "^29.7.0",
|
|
101
|
-
"@sveltejs/vite-plugin-svelte": "^
|
|
102
|
-
"@testing-library/jest-dom": "^6.3
|
|
103
|
-
"@testing-library/user-event": "^14.
|
|
104
|
-
"@
|
|
105
|
-
"@
|
|
106
|
-
"@vitest/coverage-v8": "^2.0.2",
|
|
95
|
+
"@sveltejs/vite-plugin-svelte": "^5.0.3",
|
|
96
|
+
"@testing-library/jest-dom": "^6.6.3",
|
|
97
|
+
"@testing-library/user-event": "^14.6.1",
|
|
98
|
+
"@vitest/coverage-v8": "^3.1.3",
|
|
99
|
+
"@vitest/eslint-plugin": "^1.1.44",
|
|
107
100
|
"all-contributors-cli": "^6.26.1",
|
|
108
101
|
"doctoc": "^2.2.1",
|
|
109
|
-
"eslint": "^
|
|
110
|
-
"eslint-config-prettier": "^
|
|
111
|
-
"eslint-
|
|
112
|
-
"eslint-plugin-
|
|
113
|
-
"eslint-plugin-n": "^16.6.2",
|
|
114
|
-
"eslint-plugin-promise": "^6.4.0",
|
|
102
|
+
"eslint": "^9.26.0",
|
|
103
|
+
"eslint-config-prettier": "^10.1.5",
|
|
104
|
+
"eslint-plugin-jest-dom": "^5.5.0",
|
|
105
|
+
"eslint-plugin-promise": "^7.2.1",
|
|
115
106
|
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
116
|
-
"eslint-plugin-svelte": "^
|
|
117
|
-
"
|
|
118
|
-
"
|
|
107
|
+
"eslint-plugin-svelte": "^3.5.1",
|
|
108
|
+
"eslint-plugin-testing-library": "^7.1.1",
|
|
109
|
+
"eslint-plugin-unicorn": "^59.0.1",
|
|
110
|
+
"expect-type": "^1.2.1",
|
|
111
|
+
"globals": "^16.1.0",
|
|
112
|
+
"happy-dom": "^17.4.6",
|
|
119
113
|
"jest": "^29.7.0",
|
|
120
114
|
"jest-environment-jsdom": "^29.7.0",
|
|
121
|
-
"jsdom": "^
|
|
115
|
+
"jsdom": "^26.1.0",
|
|
122
116
|
"npm-run-all": "^4.1.5",
|
|
123
|
-
"prettier": "^3.
|
|
124
|
-
"prettier-plugin-svelte": "^3.
|
|
125
|
-
"svelte": "^
|
|
126
|
-
"svelte-check": "^4.
|
|
117
|
+
"prettier": "^3.5.3",
|
|
118
|
+
"prettier-plugin-svelte": "^3.3.3",
|
|
119
|
+
"svelte": "^5.28.2",
|
|
120
|
+
"svelte-check": "^4.1.7",
|
|
127
121
|
"svelte-jester": "^5.0.0",
|
|
128
|
-
"typescript": "^5.
|
|
129
|
-
"
|
|
130
|
-
"
|
|
122
|
+
"typescript": "^5.8.3",
|
|
123
|
+
"typescript-eslint": "^8.32.0",
|
|
124
|
+
"typescript-svelte-plugin": "^0.3.46",
|
|
125
|
+
"vite": "^6.3.5",
|
|
126
|
+
"vitest": "^3.1.3"
|
|
131
127
|
}
|
|
132
128
|
}
|
package/src/component-types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
import type {
|
|
3
3
|
Component as ModernComponent,
|
|
4
4
|
ComponentConstructorOptions as LegacyConstructorOptions,
|
|
@@ -45,17 +45,17 @@ export type Props<C extends Component> = ComponentProps<C>
|
|
|
45
45
|
* In Svelte 5, this is the set of variables marked as `export`'d.
|
|
46
46
|
* In Svelte 4, this is simply the instance of the component class.
|
|
47
47
|
*/
|
|
48
|
-
export type Exports<C> =
|
|
49
|
-
? C
|
|
50
|
-
: C extends ModernComponent<any, infer E>
|
|
48
|
+
export type Exports<C> = IS_MODERN_SVELTE extends true
|
|
49
|
+
? C extends ModernComponent<any, infer E>
|
|
51
50
|
? E
|
|
52
|
-
: never
|
|
51
|
+
: C & { $set: never; $on: never; $destroy: never }
|
|
52
|
+
: C
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
55
|
* Options that may be passed to `mount` when rendering the component.
|
|
56
56
|
*
|
|
57
57
|
* In Svelte 4, these are the options passed to the component constructor.
|
|
58
58
|
*/
|
|
59
|
-
export type MountOptions<C extends Component> =
|
|
60
|
-
?
|
|
61
|
-
:
|
|
59
|
+
export type MountOptions<C extends Component> = IS_MODERN_SVELTE extends true
|
|
60
|
+
? Parameters<typeof mount<Props<C>, Exports<C>>>[1]
|
|
61
|
+
: LegacyConstructorOptions<Props<C>>
|
package/src/core/index.js
CHANGED
|
@@ -7,10 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import * as LegacyCore from './legacy.js'
|
|
9
9
|
import * as ModernCore from './modern.svelte.js'
|
|
10
|
-
import {
|
|
11
|
-
createValidateOptions,
|
|
12
|
-
UnknownSvelteOptionsError,
|
|
13
|
-
} from './validate-options.js'
|
|
10
|
+
import { createValidateOptions } from './validate-options.js'
|
|
14
11
|
|
|
15
12
|
const { mount, unmount, updateProps, allowedOptions } =
|
|
16
13
|
ModernCore.IS_MODERN_SVELTE ? ModernCore : LegacyCore
|
|
@@ -18,10 +15,5 @@ const { mount, unmount, updateProps, allowedOptions } =
|
|
|
18
15
|
/** Validate component options. */
|
|
19
16
|
const validateOptions = createValidateOptions(allowedOptions)
|
|
20
17
|
|
|
21
|
-
export {
|
|
22
|
-
|
|
23
|
-
UnknownSvelteOptionsError,
|
|
24
|
-
unmount,
|
|
25
|
-
updateProps,
|
|
26
|
-
validateOptions,
|
|
27
|
-
}
|
|
18
|
+
export { mount, unmount, updateProps, validateOptions }
|
|
19
|
+
export { UnknownSvelteOptionsError } from './validate-options.js'
|
package/src/index.js
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
import { act, cleanup } from './pure.js'
|
|
1
|
+
import { act, cleanup, setup } from './pure.js'
|
|
3
2
|
|
|
4
|
-
// If we're running in a test runner that supports afterEach
|
|
5
|
-
//
|
|
3
|
+
// If we're running in a test runner that supports beforeEach/afterEach
|
|
4
|
+
// we'll automatically run setup and cleanup before and after each test
|
|
6
5
|
// this ensures that tests run in isolation from each other
|
|
7
6
|
// if you don't like this then set the STL_SKIP_AUTO_CLEANUP env variable.
|
|
8
|
-
if (typeof
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
if (typeof process !== 'undefined' && !process.env.STL_SKIP_AUTO_CLEANUP) {
|
|
8
|
+
if (typeof beforeEach === 'function') {
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
setup()
|
|
11
|
+
})
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (typeof afterEach === 'function') {
|
|
15
|
+
afterEach(async () => {
|
|
16
|
+
await act()
|
|
17
|
+
cleanup()
|
|
18
|
+
})
|
|
19
|
+
}
|
|
13
20
|
}
|
|
14
21
|
|
|
15
22
|
// export all base queries, screen, etc.
|
package/src/pure.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
+
configure as configureDTL,
|
|
2
3
|
fireEvent as baseFireEvent,
|
|
4
|
+
getConfig as getDTLConfig,
|
|
3
5
|
getQueriesForElement,
|
|
4
6
|
prettyDOM,
|
|
5
7
|
} from '@testing-library/dom'
|
|
6
|
-
import
|
|
8
|
+
import * as Svelte from 'svelte'
|
|
7
9
|
|
|
8
10
|
import { mount, unmount, updateProps, validateOptions } from './core/index.js'
|
|
9
11
|
|
|
@@ -65,6 +67,7 @@ const render = (Component, options = {}, renderOptions = {}) => {
|
|
|
65
67
|
const queries = getQueriesForElement(baseElement, renderOptions.queries)
|
|
66
68
|
|
|
67
69
|
const target =
|
|
70
|
+
// eslint-disable-next-line unicorn/prefer-dom-node-append
|
|
68
71
|
options.target ?? baseElement.appendChild(document.createElement('div'))
|
|
69
72
|
|
|
70
73
|
targetCache.add(target)
|
|
@@ -93,7 +96,7 @@ const render = (Component, options = {}, renderOptions = {}) => {
|
|
|
93
96
|
}
|
|
94
97
|
|
|
95
98
|
updateProps(component, props)
|
|
96
|
-
await tick()
|
|
99
|
+
await Svelte.tick()
|
|
97
100
|
},
|
|
98
101
|
unmount: () => {
|
|
99
102
|
cleanupComponent(component)
|
|
@@ -102,6 +105,33 @@ const render = (Component, options = {}, renderOptions = {}) => {
|
|
|
102
105
|
}
|
|
103
106
|
}
|
|
104
107
|
|
|
108
|
+
/** @type {import('@testing-library/dom'.Config | undefined} */
|
|
109
|
+
let originalDTLConfig
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Configure `@testing-library/dom` for usage with Svelte.
|
|
113
|
+
*
|
|
114
|
+
* Ensures events fired from `@testing-library/dom`
|
|
115
|
+
* and `@testing-library/user-event` wait for Svelte
|
|
116
|
+
* to flush changes to the DOM before proceeding.
|
|
117
|
+
*/
|
|
118
|
+
const setup = () => {
|
|
119
|
+
originalDTLConfig = getDTLConfig()
|
|
120
|
+
|
|
121
|
+
configureDTL({
|
|
122
|
+
asyncWrapper: act,
|
|
123
|
+
eventWrapper: Svelte.flushSync ?? ((cb) => cb()),
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Reset dom-testing-library config. */
|
|
128
|
+
const cleanupDTL = () => {
|
|
129
|
+
if (originalDTLConfig) {
|
|
130
|
+
configureDTL(originalDTLConfig)
|
|
131
|
+
originalDTLConfig = undefined
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
105
135
|
/** Remove a component from the component cache. */
|
|
106
136
|
const cleanupComponent = (component) => {
|
|
107
137
|
const inCache = componentCache.delete(component)
|
|
@@ -116,27 +146,35 @@ const cleanupTarget = (target) => {
|
|
|
116
146
|
const inCache = targetCache.delete(target)
|
|
117
147
|
|
|
118
148
|
if (inCache && target.parentNode === document.body) {
|
|
119
|
-
|
|
149
|
+
target.remove()
|
|
120
150
|
}
|
|
121
151
|
}
|
|
122
152
|
|
|
123
|
-
/** Unmount
|
|
153
|
+
/** Unmount components, remove elements added to `<body>`, and reset `@testing-library/dom`. */
|
|
124
154
|
const cleanup = () => {
|
|
125
|
-
componentCache
|
|
126
|
-
|
|
155
|
+
for (const component of componentCache) {
|
|
156
|
+
cleanupComponent(component)
|
|
157
|
+
}
|
|
158
|
+
for (const target of targetCache) {
|
|
159
|
+
cleanupTarget(target)
|
|
160
|
+
}
|
|
161
|
+
cleanupDTL()
|
|
127
162
|
}
|
|
128
163
|
|
|
129
164
|
/**
|
|
130
165
|
* Call a function and wait for Svelte to flush pending changes.
|
|
131
166
|
*
|
|
132
|
-
* @
|
|
133
|
-
* @
|
|
167
|
+
* @template T
|
|
168
|
+
* @param {(() => Promise<T>) | () => T} [fn] - A function, which may be `async`, to call before flushing updates.
|
|
169
|
+
* @returns {Promise<T>}
|
|
134
170
|
*/
|
|
135
171
|
const act = async (fn) => {
|
|
172
|
+
let result
|
|
136
173
|
if (fn) {
|
|
137
|
-
await fn()
|
|
174
|
+
result = await fn()
|
|
138
175
|
}
|
|
139
|
-
|
|
176
|
+
await Svelte.tick()
|
|
177
|
+
return result
|
|
140
178
|
}
|
|
141
179
|
|
|
142
180
|
/**
|
|
@@ -157,18 +195,10 @@ const act = async (fn) => {
|
|
|
157
195
|
*
|
|
158
196
|
* @type {FireFunction & FireObject}
|
|
159
197
|
*/
|
|
160
|
-
const fireEvent = async (...args) =>
|
|
161
|
-
const event = baseFireEvent(...args)
|
|
162
|
-
await tick()
|
|
163
|
-
return event
|
|
164
|
-
}
|
|
198
|
+
const fireEvent = async (...args) => act(() => baseFireEvent(...args))
|
|
165
199
|
|
|
166
|
-
Object.
|
|
167
|
-
fireEvent[key] = async (...args) =>
|
|
168
|
-
|
|
169
|
-
await tick()
|
|
170
|
-
return event
|
|
171
|
-
}
|
|
172
|
-
})
|
|
200
|
+
for (const [key, baseEvent] of Object.entries(baseFireEvent)) {
|
|
201
|
+
fireEvent[key] = async (...args) => act(() => baseEvent(...args))
|
|
202
|
+
}
|
|
173
203
|
|
|
174
|
-
export { act, cleanup, fireEvent, render }
|
|
204
|
+
export { act, cleanup, fireEvent, render, setup }
|
package/src/vite.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import url from 'node:url'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Vite plugin to configure @testing-library/svelte.
|
|
@@ -50,8 +50,8 @@ const addBrowserCondition = (config) => {
|
|
|
50
50
|
const browserConditionIndex = conditions.indexOf('browser')
|
|
51
51
|
|
|
52
52
|
if (
|
|
53
|
-
nodeConditionIndex
|
|
54
|
-
(nodeConditionIndex < browserConditionIndex || browserConditionIndex
|
|
53
|
+
nodeConditionIndex !== -1 &&
|
|
54
|
+
(nodeConditionIndex < browserConditionIndex || browserConditionIndex === -1)
|
|
55
55
|
) {
|
|
56
56
|
conditions.splice(nodeConditionIndex, 0, 'browser')
|
|
57
57
|
}
|
|
@@ -77,7 +77,9 @@ const addAutoCleanup = (config) => {
|
|
|
77
77
|
setupFiles = [setupFiles]
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
setupFiles.push(
|
|
80
|
+
setupFiles.push(
|
|
81
|
+
path.join(path.dirname(url.fileURLToPath(import.meta.url)), './vitest.js')
|
|
82
|
+
)
|
|
81
83
|
|
|
82
84
|
test.setupFiles = setupFiles
|
|
83
85
|
config.test = test
|
package/src/vitest.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import { act, cleanup } from '@testing-library/svelte'
|
|
2
|
-
import {
|
|
1
|
+
import { act, cleanup, setup } from '@testing-library/svelte'
|
|
2
|
+
import { beforeEach } from 'vitest'
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
beforeEach(() => {
|
|
5
|
+
setup()
|
|
6
|
+
|
|
7
|
+
return async () => {
|
|
8
|
+
await act()
|
|
9
|
+
cleanup()
|
|
10
|
+
}
|
|
7
11
|
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
import type {
|
|
3
3
|
Component as ModernComponent,
|
|
4
4
|
ComponentConstructorOptions as LegacyConstructorOptions,
|
|
@@ -45,17 +45,17 @@ export type Props<C extends Component> = ComponentProps<C>
|
|
|
45
45
|
* In Svelte 5, this is the set of variables marked as `export`'d.
|
|
46
46
|
* In Svelte 4, this is simply the instance of the component class.
|
|
47
47
|
*/
|
|
48
|
-
export type Exports<C> =
|
|
49
|
-
? C
|
|
50
|
-
: C extends ModernComponent<any, infer E>
|
|
48
|
+
export type Exports<C> = IS_MODERN_SVELTE extends true
|
|
49
|
+
? C extends ModernComponent<any, infer E>
|
|
51
50
|
? E
|
|
52
|
-
: never
|
|
51
|
+
: C & { $set: never; $on: never; $destroy: never }
|
|
52
|
+
: C
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
55
|
* Options that may be passed to `mount` when rendering the component.
|
|
56
56
|
*
|
|
57
57
|
* In Svelte 4, these are the options passed to the component constructor.
|
|
58
58
|
*/
|
|
59
|
-
export type MountOptions<C extends Component> =
|
|
60
|
-
?
|
|
61
|
-
:
|
|
59
|
+
export type MountOptions<C extends Component> = IS_MODERN_SVELTE extends true
|
|
60
|
+
? Parameters<typeof mount<Props<C>, Exports<C>>>[1]
|
|
61
|
+
: LegacyConstructorOptions<Props<C>>
|
package/types/core/index.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
+
export { UnknownSvelteOptionsError } from "./validate-options.js";
|
|
1
2
|
export const mount: (Component: any, options: any, onDestroy: any) => any;
|
|
2
|
-
import { UnknownSvelteOptionsError } from './validate-options.js';
|
|
3
3
|
export const unmount: (component: any) => void;
|
|
4
4
|
export const updateProps: (component: any, nextProps: any) => void;
|
|
5
5
|
/** Validate component options. */
|
|
6
6
|
export const validateOptions: (options: any) => any;
|
|
7
|
-
export { UnknownSvelteOptionsError };
|
|
8
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.js"],"names":[],"mappings":";;;;AAcA,kCAAkC;AAClC,oDAA6D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-options.d.ts","sourceRoot":"","sources":["../../src/core/validate-options.js"],"names":[],"mappings":"AAiBA,
|
|
1
|
+
{"version":3,"file":"validate-options.d.ts","sourceRoot":"","sources":["../../src/core/validate-options.js"],"names":[],"mappings":"AAiBA,6DAAmD,YAAO,SAmBzD;AApCD;IACE,sDAaC;CACF"}
|
package/types/pure.d.ts
CHANGED
|
@@ -25,11 +25,12 @@ export type FireObject = { [K in import("@testing-library/dom").EventType]: (...
|
|
|
25
25
|
/**
|
|
26
26
|
* Call a function and wait for Svelte to flush pending changes.
|
|
27
27
|
*
|
|
28
|
-
* @
|
|
29
|
-
* @
|
|
28
|
+
* @template T
|
|
29
|
+
* @param {(() => Promise<T>) | () => T} [fn] - A function, which may be `async`, to call before flushing updates.
|
|
30
|
+
* @returns {Promise<T>}
|
|
30
31
|
*/
|
|
31
|
-
export function act(fn?: (() =>
|
|
32
|
-
/** Unmount
|
|
32
|
+
export function act<T>(fn?: (() => Promise<T>) | (() => T)): Promise<T>;
|
|
33
|
+
/** Unmount components, remove elements added to `<body>`, and reset `@testing-library/dom`. */
|
|
33
34
|
export function cleanup(): void;
|
|
34
35
|
/**
|
|
35
36
|
* @typedef {(...args: Parameters<import('@testing-library/dom').FireFunction>) => Promise<ReturnType<import('@testing-library/dom').FireFunction>>} FireFunction
|
|
@@ -92,4 +93,12 @@ export const fireEvent: FireFunction & FireObject;
|
|
|
92
93
|
* @returns {RenderResult<C, Q>} The rendered component and bound testing functions.
|
|
93
94
|
*/
|
|
94
95
|
export function render<C extends import("./component-types.js").Component, Q extends import("@testing-library/dom").Queries = typeof import("@testing-library/dom/types/queries.js")>(Component: import("./component-types.js").ComponentType<C>, options?: SvelteComponentOptions<C>, renderOptions?: RenderOptions<Q>): RenderResult<C, Q>;
|
|
96
|
+
/**
|
|
97
|
+
* Configure `@testing-library/dom` for usage with Svelte.
|
|
98
|
+
*
|
|
99
|
+
* Ensures events fired from `@testing-library/dom`
|
|
100
|
+
* and `@testing-library/user-event` wait for Svelte
|
|
101
|
+
* to flush changes to the DOM before proceeding.
|
|
102
|
+
*/
|
|
103
|
+
export function setup(): void;
|
|
95
104
|
//# sourceMappingURL=pure.d.ts.map
|
package/types/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":";;;mCAiBwD,CAAC,SAA5C,OAAQ,sB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