@testing-library/svelte 5.2.0 → 5.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testing-library/svelte",
3
- "version": "5.2.0",
3
+ "version": "5.2.2",
4
4
  "description": "Simple and complete Svelte testing utilities that encourage good testing practices.",
5
5
  "main": "src/index.js",
6
6
  "exports": {
@@ -53,6 +53,7 @@
53
53
  "!__tests__"
54
54
  ],
55
55
  "scripts": {
56
+ "all": "npm-run-all contributors:generate toc format types build test:vitest:* test:jest",
56
57
  "toc": "doctoc README.md",
57
58
  "lint": "prettier . --check && eslint .",
58
59
  "lint:delta": "npm-run-all -p prettier:delta eslint:delta",
@@ -62,13 +63,14 @@
62
63
  "format:delta": "npm-run-all format:prettier:delta format:eslint:delta",
63
64
  "format:prettier:delta": "prettier --write `./scripts/changed-files`",
64
65
  "format:eslint:delta": "eslint --fix `./scripts/changed-files`",
65
- "setup": "npm install && npm run validate",
66
+ "setup": "npm install && npm run all",
66
67
  "test": "vitest run --coverage",
67
68
  "test:watch": "vitest",
68
69
  "test:vitest:jsdom": "vitest run --coverage --environment jsdom",
69
70
  "test:vitest:happy-dom": "vitest run --coverage --environment happy-dom",
70
71
  "test:jest": "npx --node-options=\"--experimental-vm-modules --no-warnings\" jest --coverage",
71
72
  "types": "svelte-check",
73
+ "types:legacy": "svelte-check --tsconfig tsconfig.legacy.json",
72
74
  "validate": "npm-run-all test:vitest:* test:jest types build",
73
75
  "build": "tsc -p tsconfig.build.json",
74
76
  "contributors:add": "all-contributors add",
@@ -96,34 +98,32 @@
96
98
  "@sveltejs/vite-plugin-svelte": "^3.1.1",
97
99
  "@testing-library/jest-dom": "^6.3.0",
98
100
  "@testing-library/user-event": "^14.5.2",
99
- "@typescript-eslint/eslint-plugin": "7.8.0",
100
- "@typescript-eslint/parser": "7.8.0",
101
- "@vitest/coverage-v8": "^1.5.2",
101
+ "@typescript-eslint/eslint-plugin": "^8.0.0",
102
+ "@typescript-eslint/parser": "^8.0.0",
103
+ "@vitest/coverage-v8": "^2.0.2",
102
104
  "all-contributors-cli": "^6.26.1",
103
105
  "doctoc": "^2.2.1",
104
- "eslint": "8.57.0",
105
- "eslint-config-prettier": "9.1.0",
106
- "eslint-config-standard": "17.1.0",
107
- "eslint-plugin-import": "2.29.1",
108
- "eslint-plugin-json-files": "^4.1.0",
109
- "eslint-plugin-n": "16.6.2",
110
- "eslint-plugin-promise": "6.1.1",
111
- "eslint-plugin-simple-import-sort": "12.1.0",
112
- "eslint-plugin-svelte": "2.38.0",
113
- "eslint-plugin-vitest-globals": "1.5.0",
114
- "expect-type": "^0.19.0",
115
- "happy-dom": "^14.7.1",
106
+ "eslint": "^8.57.0",
107
+ "eslint-config-prettier": "^9.1.0",
108
+ "eslint-config-standard": "^17.1.0",
109
+ "eslint-plugin-import": "^2.29.1",
110
+ "eslint-plugin-n": "^16.6.2",
111
+ "eslint-plugin-promise": "^6.4.0",
112
+ "eslint-plugin-simple-import-sort": "^12.1.1",
113
+ "eslint-plugin-svelte": "^2.42.0",
114
+ "expect-type": "^0.20.0",
115
+ "happy-dom": "^15.7.3",
116
116
  "jest": "^29.7.0",
117
117
  "jest-environment-jsdom": "^29.7.0",
118
- "jsdom": "^24.0.0",
118
+ "jsdom": "^25.0.0",
119
119
  "npm-run-all": "^4.1.5",
120
- "prettier": "3.2.5",
121
- "prettier-plugin-svelte": "3.2.3",
120
+ "prettier": "^3.3.3",
121
+ "prettier-plugin-svelte": "^3.2.5",
122
122
  "svelte": "^3 || ^4 || ^5 || ^5.0.0-next.0",
123
- "svelte-check": "^3.6.3",
123
+ "svelte-check": "^3.8.4",
124
124
  "svelte-jester": "^5.0.0",
125
- "typescript": "^5.3.3",
126
- "vite": "^5.1.1",
127
- "vitest": "^1.5.2"
125
+ "typescript": "^5.5.3",
126
+ "vite": "^5.3.3",
127
+ "vitest": "^2.0.2"
128
128
  }
129
129
  }
@@ -0,0 +1,43 @@
1
+ import type * as Svelte from 'svelte'
2
+
3
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
+ type IS_MODERN_SVELTE = any extends Svelte.Component ? false : true
5
+
6
+ /** A compiled, imported Svelte component. */
7
+ export type Component<P> = IS_MODERN_SVELTE extends true
8
+ ? Svelte.Component<P> | Svelte.SvelteComponent<P>
9
+ : Svelte.SvelteComponent<P>
10
+
11
+ /**
12
+ * The type of an imported, compiled Svelte component.
13
+ *
14
+ * In Svelte 4, this was the Svelte component class' type.
15
+ * In Svelte 5, this distinction no longer matters.
16
+ */
17
+ export type ComponentType<C> = C extends Svelte.SvelteComponent
18
+ ? Svelte.ComponentType<C>
19
+ : C
20
+
21
+ /** The props of a component. */
22
+ export type Props<C> = Svelte.ComponentProps<C>
23
+
24
+ /**
25
+ * The exported fields of a component.
26
+ *
27
+ * In Svelte 4, this is simply the instance of the component class.
28
+ * In Svelte 5, this is the set of variables marked as `export`'d.
29
+ */
30
+ export type Exports<C> = C extends Svelte.SvelteComponent
31
+ ? C
32
+ : C extends Svelte.Component<unknown, infer E>
33
+ ? E
34
+ : never
35
+
36
+ /**
37
+ * Options that may be passed to `mount` when rendering the component.
38
+ *
39
+ * In Svelte 4, these are the options passed to the component constructor.
40
+ */
41
+ export type MountOptions<C> = IS_MODERN_SVELTE extends true
42
+ ? Parameters<typeof Svelte.mount<Props<C>, Exports<C>>>[1]
43
+ : Svelte.ComponentConstructorOptions<Props<C>>
@@ -26,6 +26,7 @@ const mount = (Component, options) => {
26
26
  const props = $state(options.props ?? {})
27
27
  const component = Svelte.mount(Component, { ...options, props })
28
28
 
29
+ Svelte.flushSync()
29
30
  propsByComponent.set(component, props)
30
31
 
31
32
  return component
@@ -34,7 +35,7 @@ const mount = (Component, options) => {
34
35
  /** Remove the component from the DOM. */
35
36
  const unmount = (component) => {
36
37
  propsByComponent.delete(component)
37
- Svelte.unmount(component)
38
+ Svelte.flushSync(() => Svelte.unmount(component))
38
39
  }
39
40
 
40
41
  /**
package/src/pure.js CHANGED
@@ -13,8 +13,8 @@ const componentCache = new Set()
13
13
  /**
14
14
  * Customize how Svelte renders the component.
15
15
  *
16
- * @template {import('svelte').SvelteComponent} C
17
- * @typedef {import('svelte').ComponentProps<C> | Partial<import('svelte').ComponentConstructorOptions<import('svelte').ComponentProps<C>>>} SvelteComponentOptions
16
+ * @template {import('./component-types.js').Component} C
17
+ * @typedef {import('./component-types.js').Props<C> | Partial<import('./component-types.js').MountOptions<C>>} SvelteComponentOptions
18
18
  */
19
19
 
20
20
  /**
@@ -30,15 +30,15 @@ const componentCache = new Set()
30
30
  /**
31
31
  * The rendered component and bound testing functions.
32
32
  *
33
- * @template {import('svelte').SvelteComponent} C
33
+ * @template {import('./component-types.js').Component} C
34
34
  * @template {import('@testing-library/dom').Queries} [Q=typeof import('@testing-library/dom').queries]
35
35
  *
36
36
  * @typedef {{
37
37
  * container: HTMLElement
38
38
  * baseElement: HTMLElement
39
- * component: C
39
+ * component: import('./component-types.js').Exports<C>
40
40
  * debug: (el?: HTMLElement | DocumentFragment) => void
41
- * rerender: (props: Partial<import('svelte').ComponentProps<C>>) => Promise<void>
41
+ * rerender: (props: Partial<import('./component-types.js').Props<C>>) => Promise<void>
42
42
  * unmount: () => void
43
43
  * } & {
44
44
  * [P in keyof Q]: import('@testing-library/dom').BoundFunction<Q[P]>
@@ -48,10 +48,10 @@ const componentCache = new Set()
48
48
  /**
49
49
  * Render a component into the document.
50
50
  *
51
- * @template {import('svelte').SvelteComponent} C
51
+ * @template {import('./component-types.js').Component} C
52
52
  * @template {import('@testing-library/dom').Queries} [Q=typeof import('@testing-library/dom').queries]
53
53
  *
54
- * @param {import('svelte').ComponentType<C>} Component - The component to render.
54
+ * @param {import('./component-types.js').ComponentType<C>} Component - The component to render.
55
55
  * @param {SvelteComponentOptions<C>} options - Customize how Svelte renders the component.
56
56
  * @param {RenderOptions<Q>} renderOptions - Customize how Testing Library sets up the document and binds queries.
57
57
  * @returns {RenderResult<C, Q>} The rendered component and bound testing functions.
@@ -1 +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"}
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,yDAQC;AAED,yCAAyC;AACzC,8CAGC;AAED;;;;GAIG;AACH,kEAGC"}
package/types/pure.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Customize how Svelte renders the component.
3
3
  */
4
- export type SvelteComponentOptions<C extends import("svelte").SvelteComponent> = import("svelte").ComponentProps<C> | Partial<import("svelte").ComponentConstructorOptions<import("svelte").ComponentProps<C>>>;
4
+ export type SvelteComponentOptions<C extends any> = import("./component-types.js").Props<C> | Partial<import("./component-types.js").MountOptions<C>>;
5
5
  /**
6
6
  * Customize how Testing Library sets up the document and binds queries.
7
7
  */
@@ -12,12 +12,12 @@ export type RenderOptions<Q extends import("@testing-library/dom").Queries = typ
12
12
  /**
13
13
  * The rendered component and bound testing functions.
14
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")> = {
15
+ export type RenderResult<C extends any, Q extends import("@testing-library/dom").Queries = typeof import("@testing-library/dom/types/queries.js")> = {
16
16
  container: HTMLElement;
17
17
  baseElement: HTMLElement;
18
- component: C;
18
+ component: import("./component-types.js").Exports<C>;
19
19
  debug: (el?: HTMLElement | DocumentFragment) => void;
20
- rerender: (props: Partial<import("svelte").ComponentProps<C>>) => Promise<void>;
20
+ rerender: (props: Partial<import("./component-types.js").Props<C>>) => Promise<void>;
21
21
  unmount: () => void;
22
22
  } & { [P in keyof Q]: import("@testing-library/dom").BoundFunction<Q[P]>; };
23
23
  export type FireFunction = (...args: Parameters<import("@testing-library/dom").FireFunction>) => Promise<ReturnType<import("@testing-library/dom").FireFunction>>;
@@ -51,8 +51,8 @@ export const fireEvent: FireFunction & FireObject;
51
51
  /**
52
52
  * Customize how Svelte renders the component.
53
53
  *
54
- * @template {import('svelte').SvelteComponent} C
55
- * @typedef {import('svelte').ComponentProps<C> | Partial<import('svelte').ComponentConstructorOptions<import('svelte').ComponentProps<C>>>} SvelteComponentOptions
54
+ * @template {import('./component-types.js').Component} C
55
+ * @typedef {import('./component-types.js').Props<C> | Partial<import('./component-types.js').MountOptions<C>>} SvelteComponentOptions
56
56
  */
57
57
  /**
58
58
  * Customize how Testing Library sets up the document and binds queries.
@@ -66,15 +66,15 @@ export const fireEvent: FireFunction & FireObject;
66
66
  /**
67
67
  * The rendered component and bound testing functions.
68
68
  *
69
- * @template {import('svelte').SvelteComponent} C
69
+ * @template {import('./component-types.js').Component} C
70
70
  * @template {import('@testing-library/dom').Queries} [Q=typeof import('@testing-library/dom').queries]
71
71
  *
72
72
  * @typedef {{
73
73
  * container: HTMLElement
74
74
  * baseElement: HTMLElement
75
- * component: C
75
+ * component: import('./component-types.js').Exports<C>
76
76
  * debug: (el?: HTMLElement | DocumentFragment) => void
77
- * rerender: (props: Partial<import('svelte').ComponentProps<C>>) => Promise<void>
77
+ * rerender: (props: Partial<import('./component-types.js').Props<C>>) => Promise<void>
78
78
  * unmount: () => void
79
79
  * } & {
80
80
  * [P in keyof Q]: import('@testing-library/dom').BoundFunction<Q[P]>
@@ -83,13 +83,13 @@ export const fireEvent: FireFunction & FireObject;
83
83
  /**
84
84
  * Render a component into the document.
85
85
  *
86
- * @template {import('svelte').SvelteComponent} C
86
+ * @template {import('./component-types.js').Component} C
87
87
  * @template {import('@testing-library/dom').Queries} [Q=typeof import('@testing-library/dom').queries]
88
88
  *
89
- * @param {import('svelte').ComponentType<C>} Component - The component to render.
89
+ * @param {import('./component-types.js').ComponentType<C>} Component - The component to render.
90
90
  * @param {SvelteComponentOptions<C>} options - Customize how Svelte renders the component.
91
91
  * @param {RenderOptions<Q>} renderOptions - Customize how Testing Library sets up the document and binds queries.
92
92
  * @returns {RenderResult<C, Q>} The rendered component and bound testing functions.
93
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>;
94
+ export function render<C extends any, 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>;
95
95
  //# sourceMappingURL=pure.d.ts.map
@@ -1 +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,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