@testing-library/svelte 5.2.0-next.1 → 5.2.0-next.2

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 CHANGED
@@ -12,17 +12,18 @@
12
12
 
13
13
  <p>Simple and complete Svelte testing utilities that encourage good testing practices.</p>
14
14
 
15
- [**Read The Docs**](https://testing-library.com/docs/svelte-testing-library/intro) |
16
- [Edit the docs](https://github.com/testing-library/testing-library-docs)
15
+ [**Read The Docs**][stl-docs] | [Edit the docs][stl-docs-repo]
17
16
 
18
17
  <!-- prettier-ignore-start -->
19
18
  [![Build Status][build-badge]][build]
20
19
  [![Code Coverage][coverage-badge]][coverage]
21
- [![version][version-badge]][package] [![downloads][downloads-badge]][npmtrends]
20
+ [![version][version-badge]][package]
21
+ [![downloads][downloads-badge]][downloads]
22
22
  [![MIT License][license-badge]][license]
23
23
 
24
- [![All Contributors](https://img.shields.io/badge/all_contributors-8-orange.svg?style=flat-square)](#contributors-)
25
- [![PRs Welcome][prs-badge]][prs] [![Code of Conduct][coc-badge]][coc]
24
+ [![All Contributors][contributors-badge]][contributors]
25
+ [![PRs Welcome][prs-badge]][prs]
26
+ [![Code of Conduct][coc-badge]][coc]
26
27
  [![Discord][discord-badge]][discord]
27
28
 
28
29
  [![Watch on GitHub][github-watch-badge]][github-watch]
@@ -33,6 +34,33 @@
33
34
 
34
35
  <hr />
35
36
 
37
+ [stl-docs]: https://testing-library.com/docs/svelte-testing-library/intro
38
+ [stl-docs-repo]: https://github.com/testing-library/testing-library-docs
39
+ [build-badge]: https://img.shields.io/github/actions/workflow/status/testing-library/svelte-testing-library/release.yml?style=flat-square
40
+ [build]: https://github.com/testing-library/svelte-testing-library/actions
41
+ [coverage-badge]: https://img.shields.io/codecov/c/github/testing-library/svelte-testing-library.svg?style=flat-square
42
+ [coverage]: https://codecov.io/github/testing-library/svelte-testing-library
43
+ [version-badge]: https://img.shields.io/npm/v/@testing-library/svelte.svg?style=flat-square
44
+ [package]: https://www.npmjs.com/package/@testing-library/svelte
45
+ [downloads-badge]: https://img.shields.io/npm/dm/@testing-library/svelte.svg?style=flat-square
46
+ [downloads]: http://www.npmtrends.com/@testing-library/svelte
47
+ [license-badge]: https://img.shields.io/github/license/testing-library/svelte-testing-library?color=b&style=flat-square
48
+ [license]: https://github.com/testing-library/svelte-testing-library/blob/main/LICENSE
49
+ [contributors-badge]: https://img.shields.io/badge/all_contributors-8-orange.svg?style=flat-square
50
+ [contributors]: #contributors
51
+ [prs-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square
52
+ [prs]: http://makeapullrequest.com
53
+ [coc-badge]: https://img.shields.io/badge/code%20of-conduct-ff69b4.svg?style=flat-square
54
+ [coc]: https://github.com/testing-library/svelte-testing-library/blob/main/CODE_OF_CONDUCT.md
55
+ [discord-badge]: https://img.shields.io/discord/723559267868737556.svg?color=7389D8&labelColor=6A7EC2&logo=discord&logoColor=ffffff&style=flat-square
56
+ [discord]: https://discord.gg/testing-library
57
+ [github-watch-badge]: https://img.shields.io/github/watchers/testing-library/svelte-testing-library.svg?style=social
58
+ [github-watch]: https://github.com/testing-library/svelte-testing-library/watchers
59
+ [github-star-badge]: https://img.shields.io/github/stars/testing-library/svelte-testing-library.svg?style=social
60
+ [github-star]: https://github.com/testing-library/svelte-testing-library/stargazers
61
+ [twitter]: https://twitter.com/intent/tweet?text=Check%20out%20svelte-testing-library%20by%20%40@TestingLib%20https%3A%2F%2Fgithub.com%2Ftesting-library%2Fsvelte-testing-library%20%F0%9F%91%8D
62
+ [twitter-badge]: https://img.shields.io/twitter/url/https/github.com/testing-library/svelte-testing-library.svg?style=social
63
+
36
64
  ## Table of Contents
37
65
 
38
66
  <!-- START doctoc generated TOC please keep comment here to allow auto update -->
@@ -41,31 +69,34 @@
41
69
  - [The Problem](#the-problem)
42
70
  - [This Solution](#this-solution)
43
71
  - [Installation](#installation)
72
+ - [Setup](#setup)
44
73
  - [Docs](#docs)
45
74
  - [Issues](#issues)
46
75
  - [🐛 Bugs](#-bugs)
47
76
  - [💡 Feature Requests](#-feature-requests)
48
77
  - [❓ Questions](#-questions)
49
78
  - [Contributors](#contributors)
50
- - [LICENSE](#license)
51
79
 
52
80
  <!-- END doctoc generated TOC please keep comment here to allow auto update -->
53
81
 
54
82
  ## The Problem
55
83
 
56
- You want to write tests for your Svelte components so that they avoid including implementation
57
- details, and are maintainable in the long run.
84
+ You want to write maintainable tests for your [Svelte][svelte] components.
85
+
86
+ [svelte]: https://svelte.dev/
58
87
 
59
88
  ## This Solution
60
89
 
61
- The `svelte-testing-library` is a very lightweight solution for testing Svelte
62
- components. It provides light utility functions on top of `svelte` and
63
- `dom-testing-library`, in a way that encourages better testing practices. Its
64
- primary guiding principle is:
90
+ `@testing-library/svelte` is a lightweight library for testing Svelte
91
+ components. It provides functions on top of `svelte` and
92
+ `@testing-library/dom` so you can mount Svelte components and query their
93
+ rendered output in the DOM. Its primary guiding principle is:
65
94
 
66
95
  > [The more your tests resemble the way your software is used, the more
67
96
  > confidence they can give you.][guiding-principle]
68
97
 
98
+ [guiding-principle]: https://twitter.com/kentcdodds/status/977018512689455106
99
+
69
100
  ## Installation
70
101
 
71
102
  This module is distributed via [npm][npm] which is bundled with [node][node] and
@@ -77,12 +108,18 @@ npm install --save-dev @testing-library/svelte
77
108
 
78
109
  This library supports `svelte` versions `3`, `4`, and `5`.
79
110
 
80
- You may also be interested in installing `@testing-library/jest-dom` so you can use
81
- [the custom jest matchers](https://github.com/testing-library/jest-dom).
111
+ You may also be interested in installing `@testing-library/jest-dom` so you can
112
+ use [the custom jest matchers][jest-dom].
113
+
114
+ [npm]: https://www.npmjs.com/
115
+ [node]: https://nodejs.org
116
+ [jest-dom]: https://github.com/testing-library/jest-dom
82
117
 
83
118
  ## Setup
84
119
 
85
- We recommend using `@testing-library/svelte` with [Vitest][] as your test runner. To get started, add the `svelteTesting` plugin to your Vite or Vitest config.
120
+ We recommend using `@testing-library/svelte` with [Vitest][] as your test
121
+ runner. To get started, add the `svelteTesting` plugin to your Vite or Vitest
122
+ config.
86
123
 
87
124
  ```diff
88
125
  // vite.config.js
@@ -97,26 +134,31 @@ We recommend using `@testing-library/svelte` with [Vitest][] as your test runner
97
134
  });
98
135
  ```
99
136
 
100
- See the [setup docs][] for more detailed setup instructions, including for other test runners like Jest.
137
+ See the [setup docs][] for more detailed setup instructions, including for other
138
+ test runners like Jest.
101
139
 
102
140
  [vitest]: https://vitest.dev/
103
141
  [setup docs]: https://testing-library.com/docs/svelte-testing-library/setup
104
142
 
105
143
  ## Docs
106
144
 
107
- See the [**docs**](https://testing-library.com/docs/svelte-testing-library/intro) over at the Testing Library website.
145
+ See the [**docs**][stl-docs] over at the Testing Library website.
108
146
 
109
147
  ## Issues
110
148
 
111
149
  _Looking to contribute? Look for the [Good First Issue][good-first-issue]
112
150
  label._
113
151
 
152
+ [good-first-issue]: https://github.com/testing-library/svelte-testing-library/issues?utf8=✓&q=is%3Aissue+is%3Aopen+sort%3Areactions-%2B1-desc+label%3A"good+first+issue"+
153
+
114
154
  ### 🐛 Bugs
115
155
 
116
156
  Please file an issue for bugs, missing documentation, or unexpected behavior.
117
157
 
118
158
  [**See Bugs**][bugs]
119
159
 
160
+ [bugs]: https://github.com/testing-library/svelte-testing-library/issues?q=is%3Aissue+is%3Aopen+label%3Abug+sort%3Acreated-desc
161
+
120
162
  ### 💡 Feature Requests
121
163
 
122
164
  Please file an issue to suggest new features. Vote on feature requests by adding
@@ -124,6 +166,8 @@ a 👍. This helps maintainers prioritize what to work on.
124
166
 
125
167
  [**See Feature Requests**][requests]
126
168
 
169
+ [requests]: https://github.com/testing-library/svelte-testing-library/issues?q=is%3Aissue+sort%3Areactions-%2B1-desc+label%3Aenhancement+is%3Aopen
170
+
127
171
  ### ❓ Questions
128
172
 
129
173
  For questions related to using the library, please visit a support community
@@ -132,6 +176,8 @@ instead of filing an issue on GitHub.
132
176
  - [Discord][discord]
133
177
  - [Stack Overflow][stackoverflow]
134
178
 
179
+ [stackoverflow]: https://stackoverflow.com/questions/tagged/svelte-testing-library
180
+
135
181
  ## Contributors
136
182
 
137
183
  Thanks goes to these people ([emoji key][emojis]):
@@ -173,44 +219,5 @@ Thanks goes to these people ([emoji key][emojis]):
173
219
  This project follows the [all-contributors][all-contributors] specification.
174
220
  Contributions of any kind welcome!
175
221
 
176
- ## LICENSE
177
-
178
- [MIT](LICENSE)
179
-
180
- <!-- prettier-ignore-start -->
181
-
182
- [npm]: https://www.npmjs.com/
183
- [node]: https://nodejs.org
184
- [build-badge]: https://img.shields.io/github/actions/workflow/status/testing-library/svelte-testing-library/release.yml?style=flat-square
185
- [build]: https://github.com/testing-library/svelte-testing-library/actions
186
- [coverage-badge]: https://img.shields.io/codecov/c/github/testing-library/svelte-testing-library.svg?style=flat-square
187
- [coverage]: https://codecov.io/github/testing-library/svelte-testing-library
188
- [version-badge]: https://img.shields.io/npm/v/@testing-library/svelte.svg?style=flat-square
189
- [package]: https://www.npmjs.com/package/@testing-library/svelte
190
- [downloads-badge]: https://img.shields.io/npm/dm/@testing-library/svelte.svg?style=flat-square
191
- [npmtrends]: http://www.npmtrends.com/@testing-library/svelte
192
- [discord-badge]: https://img.shields.io/discord/723559267868737556.svg?color=7389D8&labelColor=6A7EC2&logo=discord&logoColor=ffffff&style=flat-square
193
- [discord]: https://discord.gg/testing-library
194
- [license-badge]: https://img.shields.io/github/license/testing-library/svelte-testing-library?color=b&style=flat-square
195
- [license]: https://github.com/testing-library/svelte-testing-library/blob/main/LICENSE
196
- [prs-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square
197
- [prs]: http://makeapullrequest.com
198
- [donate-badge]: https://img.shields.io/badge/$-support-green.svg?style=flat-square
199
- [coc-badge]: https://img.shields.io/badge/code%20of-conduct-ff69b4.svg?style=flat-square
200
- [coc]: https://github.com/testing-library/svelte-testing-library/blob/main/CODE_OF_CONDUCT.md
201
- [github-watch-badge]: https://img.shields.io/github/watchers/testing-library/svelte-testing-library.svg?style=social
202
- [github-watch]: https://github.com/testing-library/svelte-testing-library/watchers
203
- [github-star-badge]: https://img.shields.io/github/stars/testing-library/svelte-testing-library.svg?style=social
204
- [github-star]: https://github.com/testing-library/svelte-testing-library/stargazers
205
- [twitter]: https://twitter.com/intent/tweet?text=Check%20out%20svelte-testing-library%20by%20%40@TestingLib%20https%3A%2F%2Fgithub.com%2Ftesting-library%2Fsvelte-testing-library%20%F0%9F%91%8D
206
- [twitter-badge]: https://img.shields.io/twitter/url/https/github.com/testing-library/svelte-testing-library.svg?style=social
207
222
  [emojis]: https://github.com/all-contributors/all-contributors#emoji-key
208
223
  [all-contributors]: https://github.com/all-contributors/all-contributors
209
- [set-immediate]: https://developer.mozilla.org/en-US/docs/Web/API/Window/setImmediate
210
- [guiding-principle]: https://twitter.com/kentcdodds/status/977018512689455106
211
- [bugs]: https://github.com/testing-library/svelte-testing-library/issues?q=is%3Aissue+is%3Aopen+label%3Abug+sort%3Acreated-desc
212
- [requests]: https://github.com/testing-library/svelte-testing-library/issues?q=is%3Aissue+sort%3Areactions-%2B1-desc+label%3Aenhancement+is%3Aopen
213
- [good-first-issue]: https://github.com/testing-library/svelte-testing-library/issues?utf8=✓&q=is%3Aissue+is%3Aopen+sort%3Areactions-%2B1-desc+label%3A"good+first+issue"+
214
- [stackoverflow]: https://stackoverflow.com/questions/tagged/svelte-testing-library
215
-
216
- <!-- prettier-ignore-end -->
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testing-library/svelte",
3
- "version": "5.2.0-next.1",
3
+ "version": "5.2.0-next.2",
4
4
  "description": "Simple and complete Svelte testing utilities that encourage good testing practices.",
5
5
  "main": "src/index.js",
6
6
  "exports": {
@@ -13,6 +13,7 @@
13
13
  "default": "./src/index.js"
14
14
  },
15
15
  "./vitest": {
16
+ "types": "./types/vitest.d.ts",
16
17
  "default": "./src/vitest.js"
17
18
  },
18
19
  "./vite": {
@@ -26,7 +27,7 @@
26
27
  "homepage": "https://github.com/testing-library/svelte-testing-library#readme",
27
28
  "repository": {
28
29
  "type": "git",
29
- "url": "https://github.com/testing-library/svelte-testing-library"
30
+ "url": "git+https://github.com/testing-library/svelte-testing-library.git"
30
31
  },
31
32
  "bugs": {
32
33
  "url": "https://github.com/testing-library/svelte-testing-library/issues"
@@ -49,7 +50,6 @@
49
50
  "files": [
50
51
  "src",
51
52
  "types",
52
- "!*.test-d.ts",
53
53
  "!__tests__"
54
54
  ],
55
55
  "scripts": {
@@ -69,7 +69,8 @@
69
69
  "test:vitest:happy-dom": "vitest run --coverage --environment happy-dom",
70
70
  "test:jest": "npx --node-options=\"--experimental-vm-modules --no-warnings\" jest --coverage",
71
71
  "types": "svelte-check",
72
- "validate": "npm-run-all test:vitest:* test:jest types",
72
+ "validate": "npm-run-all test:vitest:* test:jest types build",
73
+ "build": "tsc -p tsconfig.build.json",
73
74
  "contributors:add": "all-contributors add",
74
75
  "contributors:generate": "all-contributors generate",
75
76
  "preview-release": "./scripts/preview-release"
package/src/index.js CHANGED
@@ -16,11 +16,7 @@ if (typeof afterEach === 'function' && !process.env.STL_SKIP_AUTO_CLEANUP) {
16
16
  export * from '@testing-library/dom'
17
17
 
18
18
  // export svelte-specific functions and custom `fireEvent`
19
- // `fireEvent` must be a named export to take priority over wildcard export above
20
- export {
21
- act,
22
- cleanup,
23
- fireEvent,
24
- render,
25
- UnknownSvelteOptionsError,
26
- } from './pure.js'
19
+ export { UnknownSvelteOptionsError } from './core/index.js'
20
+ export * from './pure.js'
21
+ // `fireEvent` must be named to take priority over wildcard from @testing-library/dom
22
+ export { fireEvent } from './pure.js'
package/src/pure.js CHANGED
@@ -1,21 +1,61 @@
1
1
  import {
2
- fireEvent as dtlFireEvent,
2
+ fireEvent as baseFireEvent,
3
3
  getQueriesForElement,
4
4
  prettyDOM,
5
5
  } from '@testing-library/dom'
6
6
  import { tick } from 'svelte'
7
7
 
8
- import {
9
- mount,
10
- UnknownSvelteOptionsError,
11
- unmount,
12
- updateProps,
13
- validateOptions,
14
- } from './core/index.js'
8
+ import { mount, unmount, updateProps, validateOptions } from './core/index.js'
15
9
 
16
10
  const targetCache = new Set()
17
11
  const componentCache = new Set()
18
12
 
13
+ /**
14
+ * Customize how Svelte renders the component.
15
+ *
16
+ * @template {import('svelte').SvelteComponent} C
17
+ * @typedef {import('svelte').ComponentProps<C> | Partial<import('svelte').ComponentConstructorOptions<import('svelte').ComponentProps<C>>>} SvelteComponentOptions
18
+ */
19
+
20
+ /**
21
+ * Customize how Testing Library sets up the document and binds queries.
22
+ *
23
+ * @template {import('@testing-library/dom').Queries} [Q=typeof import('@testing-library/dom').queries]
24
+ * @typedef {{
25
+ * baseElement?: HTMLElement
26
+ * queries?: Q
27
+ * }} RenderOptions
28
+ */
29
+
30
+ /**
31
+ * The rendered component and bound testing functions.
32
+ *
33
+ * @template {import('svelte').SvelteComponent} C
34
+ * @template {import('@testing-library/dom').Queries} [Q=typeof import('@testing-library/dom').queries]
35
+ *
36
+ * @typedef {{
37
+ * container: HTMLElement
38
+ * baseElement: HTMLElement
39
+ * component: C
40
+ * debug: (el?: HTMLElement | DocumentFragment) => void
41
+ * rerender: (props: Partial<import('svelte').ComponentProps<C>>) => Promise<void>
42
+ * unmount: () => void
43
+ * } & {
44
+ * [P in keyof Q]: import('@testing-library/dom').BoundFunction<Q[P]>
45
+ * }} RenderResult
46
+ */
47
+
48
+ /**
49
+ * Render a component into the document.
50
+ *
51
+ * @template {import('svelte').SvelteComponent} C
52
+ * @template {import('@testing-library/dom').Queries} [Q=typeof import('@testing-library/dom').queries]
53
+ *
54
+ * @param {import('svelte').ComponentType<C>} Component - The component to render.
55
+ * @param {SvelteComponentOptions<C>} options - Customize how Svelte renders the component.
56
+ * @param {RenderOptions<Q>} renderOptions - Customize how Testing Library sets up the document and binds queries.
57
+ * @returns {RenderResult<C, Q>} The rendered component and bound testing functions.
58
+ */
19
59
  const render = (Component, options = {}, renderOptions = {}) => {
20
60
  options = validateOptions(options)
21
61
 
@@ -62,6 +102,7 @@ const render = (Component, options = {}, renderOptions = {}) => {
62
102
  }
63
103
  }
64
104
 
105
+ /** Remove a component from the component cache. */
65
106
  const cleanupComponent = (component) => {
66
107
  const inCache = componentCache.delete(component)
67
108
 
@@ -70,6 +111,7 @@ const cleanupComponent = (component) => {
70
111
  }
71
112
  }
72
113
 
114
+ /** Remove a target element from the target cache. */
73
115
  const cleanupTarget = (target) => {
74
116
  const inCache = targetCache.delete(target)
75
117
 
@@ -78,11 +120,18 @@ const cleanupTarget = (target) => {
78
120
  }
79
121
  }
80
122
 
123
+ /** Unmount all components and remove elements added to `<body>`. */
81
124
  const cleanup = () => {
82
125
  componentCache.forEach(cleanupComponent)
83
126
  targetCache.forEach(cleanupTarget)
84
127
  }
85
128
 
129
+ /**
130
+ * Call a function and wait for Svelte to flush pending changes.
131
+ *
132
+ * @param {() => unknown} [fn] - A function, which may be `async`, to call before flushing updates.
133
+ * @returns {Promise<void>}
134
+ */
86
135
  const act = async (fn) => {
87
136
  if (fn) {
88
137
  await fn()
@@ -90,18 +139,36 @@ const act = async (fn) => {
90
139
  return tick()
91
140
  }
92
141
 
142
+ /**
143
+ * @typedef {(...args: Parameters<import('@testing-library/dom').FireFunction>) => Promise<ReturnType<import('@testing-library/dom').FireFunction>>} FireFunction
144
+ */
145
+
146
+ /**
147
+ * @typedef {{
148
+ * [K in import('@testing-library/dom').EventType]: (...args: Parameters<import('@testing-library/dom').FireObject[K]>) => Promise<ReturnType<import('@testing-library/dom').FireObject[K]>>
149
+ * }} FireObject
150
+ */
151
+
152
+ /**
153
+ * Fire an event on an element.
154
+ *
155
+ * Consider using `@testing-library/user-event` instead, if possible.
156
+ * @see https://testing-library.com/docs/user-event/intro/
157
+ *
158
+ * @type {FireFunction & FireObject}
159
+ */
93
160
  const fireEvent = async (...args) => {
94
- const event = dtlFireEvent(...args)
161
+ const event = baseFireEvent(...args)
95
162
  await tick()
96
163
  return event
97
164
  }
98
165
 
99
- Object.keys(dtlFireEvent).forEach((key) => {
166
+ Object.keys(baseFireEvent).forEach((key) => {
100
167
  fireEvent[key] = async (...args) => {
101
- const event = dtlFireEvent[key](...args)
168
+ const event = baseFireEvent[key](...args)
102
169
  await tick()
103
170
  return event
104
171
  }
105
172
  })
106
173
 
107
- export { act, cleanup, fireEvent, render, UnknownSvelteOptionsError }
174
+ export { act, cleanup, fireEvent, render }
@@ -0,0 +1,8 @@
1
+ export const mount: (Component: any, options: any, onDestroy: any) => any;
2
+ import { UnknownSvelteOptionsError } from './validate-options.js';
3
+ export const unmount: (component: any) => void;
4
+ export const updateProps: (component: any, nextProps: any) => void;
5
+ /** Validate component options. */
6
+ export const validateOptions: (options: any) => any;
7
+ export { UnknownSvelteOptionsError };
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.js"],"names":[],"mappings":";0CAYO,uBAAuB;;;AAK9B,kCAAkC;AAClC,oDAA6D"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Legacy rendering core for svelte-testing-library.
3
+ *
4
+ * Supports Svelte <= 4.
5
+ */
6
+ /** Allowed options for the component constructor. */
7
+ export const allowedOptions: string[];
8
+ /**
9
+ * Mount the component into the DOM.
10
+ *
11
+ * The `onDestroy` callback is included for strict backwards compatibility
12
+ * with previous versions of this library. It's mostly unnecessary logic.
13
+ */
14
+ export function mount(Component: any, options: any, onDestroy: any): any;
15
+ /** Remove the component from the DOM. */
16
+ export function unmount(component: any): void;
17
+ /** Update the component's props. */
18
+ export function updateProps(component: any, nextProps: any): void;
19
+ //# sourceMappingURL=legacy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legacy.d.ts","sourceRoot":"","sources":["../../src/core/legacy.js"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,qDAAqD;AACrD,sCAQC;AAED;;;;;GAKG;AACH,yEAUC;AAED,yCAAyC;AACzC,8CAEC;AAED,oCAAoC;AACpC,kEAEC"}
@@ -0,0 +1,15 @@
1
+ /** Allowed options to the `mount` call. */
2
+ export const allowedOptions: string[];
3
+ /** Whether we're using Svelte >= 5. */
4
+ export const IS_MODERN_SVELTE: boolean;
5
+ /** Mount the component into the DOM. */
6
+ export function mount(Component: any, options: any): any;
7
+ /** Remove the component from the DOM. */
8
+ export function unmount(component: any): void;
9
+ /**
10
+ * Update the component's props.
11
+ *
12
+ * Relies on the `$state` signal added in `mount`.
13
+ */
14
+ export function updateProps(component: any, nextProps: any): void;
15
+ //# sourceMappingURL=modern.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modern.svelte.d.ts","sourceRoot":"","sources":["../../src/core/modern.svelte.js"],"names":[],"mappings":"AAaA,2CAA2C;AAC3C,sCAOC;AAXD,uCAAuC;AACvC,uCAA2D;AAY3D,wCAAwC;AACxC,yDAOC;AAED,yCAAyC;AACzC,8CAGC;AAED;;;;GAIG;AACH,kEAGC"}
@@ -0,0 +1,5 @@
1
+ export function createValidateOptions(allowedOptions: any): (options: any) => any;
2
+ export class UnknownSvelteOptionsError extends TypeError {
3
+ constructor(unknownOptions: any, allowedOptions: any);
4
+ }
5
+ //# sourceMappingURL=validate-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-options.d.ts","sourceRoot":"","sources":["../../src/core/validate-options.js"],"names":[],"mappings":"AAiBA,kFAmBC;AApCD;IACE,sDAaC;CACF"}
package/types/index.d.ts CHANGED
@@ -1,82 +1,5 @@
1
- // Type definitions for Svelte Testing Library
2
- // Project: https://github.com/testing-library/svelte-testing-library
3
- // Definitions by: Rahim Alwer <https://github.com/mihar-22>
4
-
5
- import {
6
- BoundFunction,
7
- EventType,
8
- Queries,
9
- queries,
10
- } from '@testing-library/dom'
11
- import {
12
- ComponentConstructorOptions,
13
- ComponentProps,
14
- SvelteComponent,
15
- } from 'svelte'
16
-
17
- export * from '@testing-library/dom'
18
-
19
- type SvelteComponentOptions<C extends SvelteComponent> =
20
- | ComponentProps<C>
21
- | Partial<ComponentConstructorOptions<ComponentProps<C>>>
22
-
23
- type Constructor<T> = new (...args: any[]) => T
24
-
25
- /**
26
- * Render a Component into the Document.
27
- */
28
- export type RenderResult<
29
- C extends SvelteComponent,
30
- Q extends Queries = typeof queries,
31
- > = {
32
- container: HTMLElement
33
- baseElement: HTMLElement
34
- component: C
35
- debug: (el?: HTMLElement | DocumentFragment) => void
36
- rerender: (props: Partial<ComponentProps<C>>) => Promise<void>
37
- unmount: () => void
38
- } & { [P in keyof Q]: BoundFunction<Q[P]> }
39
-
40
- export interface RenderOptions<Q extends Queries = typeof queries> {
41
- baseElement?: HTMLElement
42
- queries?: Q
43
- }
44
-
45
- export function render<
46
- C extends SvelteComponent,
47
- Q extends Queries = typeof queries,
48
- >(
49
- component: Constructor<C>,
50
- componentOptions?: SvelteComponentOptions<C>,
51
- renderOptions?: RenderOptions<Q>
52
- ): RenderResult<C, Q>
53
-
54
- /**
55
- * Unmounts trees that were mounted with render.
56
- */
57
- export function cleanup(): void
58
-
59
- /**
60
- * Fires DOM events on an element provided by @testing-library/dom. Since Svelte needs to flush
61
- * pending state changes via `tick`, these methods have been override and now return a promise.
62
- */
63
- export type FireFunction = (
64
- element: Document | Element | Window,
65
- event: Event
66
- ) => Promise<boolean>
67
-
68
- export type FireObject = {
69
- [K in EventType]: (
70
- element: Document | Element | Window,
71
- options?: {}
72
- ) => Promise<boolean>
73
- }
74
-
75
- export const fireEvent: FireFunction & FireObject
76
-
77
- /**
78
- * Calls a function and notifies Svelte to flush any pending state changes.
79
- *
80
- * If the function returns a Promise, that Promise will be resolved first.
81
- */
82
- export function act(fn?: () => unknown): Promise<void>
1
+ export * from "@testing-library/dom";
2
+ export * from "./pure.js";
3
+ export { UnknownSvelteOptionsError } from "./core/index.js";
4
+ export { fireEvent } from "./pure.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":""}
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Customize how Svelte renders the component.
3
+ */
4
+ export type SvelteComponentOptions<C extends import("svelte").SvelteComponent> = import("svelte").ComponentProps<C> | Partial<import("svelte").ComponentConstructorOptions<import("svelte").ComponentProps<C>>>;
5
+ /**
6
+ * Customize how Testing Library sets up the document and binds queries.
7
+ */
8
+ export type RenderOptions<Q extends import("@testing-library/dom").Queries = typeof import("@testing-library/dom/types/queries.js")> = {
9
+ baseElement?: HTMLElement;
10
+ queries?: Q;
11
+ };
12
+ /**
13
+ * The rendered component and bound testing functions.
14
+ */
15
+ export type RenderResult<C extends import("svelte").SvelteComponent, Q extends import("@testing-library/dom").Queries = typeof import("@testing-library/dom/types/queries.js")> = {
16
+ container: HTMLElement;
17
+ baseElement: HTMLElement;
18
+ component: C;
19
+ debug: (el?: HTMLElement | DocumentFragment) => void;
20
+ rerender: (props: Partial<import("svelte").ComponentProps<C>>) => Promise<void>;
21
+ unmount: () => void;
22
+ } & { [P in keyof Q]: import("@testing-library/dom").BoundFunction<Q[P]>; };
23
+ export type FireFunction = (...args: Parameters<import("@testing-library/dom").FireFunction>) => Promise<ReturnType<import("@testing-library/dom").FireFunction>>;
24
+ export type FireObject = { [K in import("@testing-library/dom").EventType]: (...args: Parameters<import("@testing-library/dom").FireObject[K]>) => Promise<ReturnType<import("@testing-library/dom").FireObject[K]>>; };
25
+ /**
26
+ * Call a function and wait for Svelte to flush pending changes.
27
+ *
28
+ * @param {() => unknown} [fn] - A function, which may be `async`, to call before flushing updates.
29
+ * @returns {Promise<void>}
30
+ */
31
+ export function act(fn?: (() => unknown) | undefined): Promise<void>;
32
+ /** Unmount all components and remove elements added to `<body>`. */
33
+ export function cleanup(): void;
34
+ /**
35
+ * @typedef {(...args: Parameters<import('@testing-library/dom').FireFunction>) => Promise<ReturnType<import('@testing-library/dom').FireFunction>>} FireFunction
36
+ */
37
+ /**
38
+ * @typedef {{
39
+ * [K in import('@testing-library/dom').EventType]: (...args: Parameters<import('@testing-library/dom').FireObject[K]>) => Promise<ReturnType<import('@testing-library/dom').FireObject[K]>>
40
+ * }} FireObject
41
+ */
42
+ /**
43
+ * Fire an event on an element.
44
+ *
45
+ * Consider using `@testing-library/user-event` instead, if possible.
46
+ * @see https://testing-library.com/docs/user-event/intro/
47
+ *
48
+ * @type {FireFunction & FireObject}
49
+ */
50
+ export const fireEvent: FireFunction & FireObject;
51
+ /**
52
+ * Customize how Svelte renders the component.
53
+ *
54
+ * @template {import('svelte').SvelteComponent} C
55
+ * @typedef {import('svelte').ComponentProps<C> | Partial<import('svelte').ComponentConstructorOptions<import('svelte').ComponentProps<C>>>} SvelteComponentOptions
56
+ */
57
+ /**
58
+ * Customize how Testing Library sets up the document and binds queries.
59
+ *
60
+ * @template {import('@testing-library/dom').Queries} [Q=typeof import('@testing-library/dom').queries]
61
+ * @typedef {{
62
+ * baseElement?: HTMLElement
63
+ * queries?: Q
64
+ * }} RenderOptions
65
+ */
66
+ /**
67
+ * The rendered component and bound testing functions.
68
+ *
69
+ * @template {import('svelte').SvelteComponent} C
70
+ * @template {import('@testing-library/dom').Queries} [Q=typeof import('@testing-library/dom').queries]
71
+ *
72
+ * @typedef {{
73
+ * container: HTMLElement
74
+ * baseElement: HTMLElement
75
+ * component: C
76
+ * debug: (el?: HTMLElement | DocumentFragment) => void
77
+ * rerender: (props: Partial<import('svelte').ComponentProps<C>>) => Promise<void>
78
+ * unmount: () => void
79
+ * } & {
80
+ * [P in keyof Q]: import('@testing-library/dom').BoundFunction<Q[P]>
81
+ * }} RenderResult
82
+ */
83
+ /**
84
+ * Render a component into the document.
85
+ *
86
+ * @template {import('svelte').SvelteComponent} C
87
+ * @template {import('@testing-library/dom').Queries} [Q=typeof import('@testing-library/dom').queries]
88
+ *
89
+ * @param {import('svelte').ComponentType<C>} Component - The component to render.
90
+ * @param {SvelteComponentOptions<C>} options - Customize how Svelte renders the component.
91
+ * @param {RenderOptions<Q>} renderOptions - Customize how Testing Library sets up the document and binds queries.
92
+ * @returns {RenderResult<C, Q>} The rendered component and bound testing functions.
93
+ */
94
+ export function render<C extends import("svelte").SvelteComponent, Q extends import("@testing-library/dom").Queries = typeof import("@testing-library/dom/types/queries.js")>(Component: import("svelte").ComponentType<C>, options?: SvelteComponentOptions<C>, renderOptions?: RenderOptions<Q>): RenderResult<C, Q>;
95
+ //# sourceMappingURL=pure.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pure.d.ts","sourceRoot":"","sources":["../src/pure.js"],"names":[],"mappings":";;;mCAegD,CAAC,SAApC,OAAQ,QAAQ,EAAE,eAAgB,IAClC,OAAO,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,OAAO,QAAQ,EAAE,2BAA2B,CAAC,OAAO,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;;;;0BAMpF,CAAC,SAA3C,OAAQ,sBAAsB,EAAE,OAAQ,6DACxC;IACZ,WAAe,CAAC,EAAE,WAAW,CAAA;IAC7B,OAAW,CAAC,EAAE,CAAC,CAAA;CACZ;;;;yBAM4C,CAAC,SAApC,OAAQ,QAAQ,EAAE,eAAgB,EACQ,CAAC,SAA3C,OAAQ,sBAAsB,EAAE,OAAQ,6DAExC;IACZ,SAAa,EAAE,WAAW,CAAA;IAC1B,WAAe,EAAE,WAAW,CAAA;IAC5B,SAAa,EAAE,CAAC,CAAA;IAChB,KAAS,EAAE,CAAC,EAAE,CAAC,EAAE,WAAW,GAAG,gBAAgB,KAAK,IAAI,CAAA;IACxD,QAAY,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,OAAO,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACnF,OAAW,EAAE,MAAM,IAAI,CAAA;CACpB,GAAG,GACD,CAAY,IAAP,MAAM,CAAC,GAAG,OAAO,sBAAsB,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GACnE;2BAkGS,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,sBAAsB,EAAE,YAAY,CAAC,KAAK,OAAO,CAAC,UAAU,CAAC,OAAO,sBAAsB,EAAE,YAAY,CAAC,CAAC;yBAItI,GACP,CAA6C,IAAxC,OAAO,sBAAsB,EAAE,SAAS,GAAG,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,sBAAsB,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,UAAU,CAAC,OAAO,sBAAsB,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,GAC1L;AApBJ;;;;;GAKG;AACH,gCAHiB,OAAO,gBACX,OAAO,CAAC,IAAI,CAAC,CAOzB;AAjBD,oEAAoE;AACpE,gCAGC;AAeD;;GAEG;AAEH;;;;GAIG;AAEH;;;;;;;GAOG;AACH,wBAFU,YAAY,GAAG,UAAU,CAMlC;AAvJD;;;;;GAKG;AAEH;;;;;;;;GAQG;AAEH;;;;;;;;;;;;;;;;GAgBG;AAEH;;;;;;;;;;GAUG;AACH,uBARgD,CAAC,SAApC,OAAQ,QAAQ,EAAE,eAAgB,EACQ,CAAC,SAA3C,OAAQ,sBAAsB,EAAE,OAAQ,sEAE1C,OAAO,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,YACjC,sBAAsB,CAAC,CAAC,CAAC,kBACzB,aAAa,CAAC,CAAC,CAAC,GACd,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CA8C9B"}
package/types/vite.d.ts CHANGED
@@ -1,12 +1,5 @@
1
- import type { Plugin } from 'vite'
2
-
3
- /**
4
- * Vite plugin to configure @testing-library/svelte.
5
- *
6
- * Ensures Svelte is imported correctly in tests
7
- * and that the DOM is cleaned up after each test.
8
- */
9
- export function svelteTesting(options?: {
10
- resolveBrowser?: boolean
11
- autoCleanup?: boolean
12
- }): Plugin
1
+ export function svelteTesting({ resolveBrowser, autoCleanup, }?: {
2
+ resolveBrowser?: boolean;
3
+ autoCleanup?: boolean;
4
+ }): import("vite").Plugin;
5
+ //# sourceMappingURL=vite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../src/vite.js"],"names":[],"mappings":"AAYO,iEAHI;IAAC,cAAc,CAAC,EAAE,OAAO,CAAC;IAAC,WAAW,CAAC,EAAE,OAAO,CAAA;CAAC,GAC/C,OAAO,MAAM,EAAE,MAAM,CAoBhC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=vitest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vitest.d.ts","sourceRoot":"","sources":["../src/vitest.js"],"names":[],"mappings":""}