@noma.to/qwik-testing-library 1.4.0 → 1.5.1

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
@@ -131,7 +131,7 @@ should be installed as one of your project's `devDependencies`:
131
131
  npm install --save-dev @noma.to/qwik-testing-library @testing-library/dom
132
132
  ```
133
133
 
134
- This library supports `qwik` versions `1.7.2` and above and `@testing-library/dom` versions `10.1.0` and above.
134
+ This library supports `qwik` versions `1.12.0` and above and `@testing-library/dom` versions `10.1.0` and above.
135
135
 
136
136
  You may also be interested in installing `@testing-library/jest-dom` and `@testing-library/user-event` so you can
137
137
  use [the custom jest matchers][jest-dom] and [the user event library][user-event] to test interactions with the DOM.
@@ -162,80 +162,30 @@ npm install --save-dev happy-dom
162
162
  We recommend using `@noma.to/qwik-testing-library` with [Vitest][vitest] as your test
163
163
  runner.
164
164
 
165
- If you haven't done so already, add vitest to your project using Qwik CLI:
165
+ If you haven't done so already, install vitest:
166
166
 
167
167
  ```shell
168
- npm run qwik add vitest
168
+ npm install --save-dev vitest
169
169
  ```
170
170
 
171
171
  After that, we need to configure Vitest so it can run your tests.
172
- For this, create a _separate_ `vitest.config.ts` so you don't have to modify your project's `vite.config.ts`:
172
+ Add the `test` section to your `vite.config.ts`:
173
173
 
174
174
  ```ts
175
- // vitest.config.ts
176
-
177
- import {defineConfig, mergeConfig} from "vitest/config";
178
- import viteConfig from "./vite.config";
179
-
180
- export default defineConfig((configEnv) =>
181
- mergeConfig(
182
- viteConfig(configEnv),
183
- defineConfig({
184
- // qwik-testing-library needs to consider your project as a Qwik lib
185
- // if it's already a Qwik lib, you can remove this section
186
- build: {
187
- target: "es2020",
188
- lib: {
189
- entry: "./src/index.ts",
190
- formats: ["es", "cjs"],
191
- fileName: (format, entryName) =>
192
- `${entryName}.qwik.${format === "es" ? "mjs" : "cjs"}`,
193
- },
194
- },
195
- // configure your test environment
196
- test: {
197
- environment: "jsdom", // or "happy-dom"
198
- setupFiles: ["./vitest.setup.ts"],
199
- globals: true,
200
- },
201
- }),
202
- ),
203
- );
175
+ // vite.config.ts
176
+
177
+ test: {
178
+ environment: "jsdom", // or "happy-dom"
179
+ setupFiles: [
180
+ "@noma.to/qwik-testing-library/setup",
181
+ "@testing-library/jest-dom/vitest", // optional, for DOM matchers
182
+ ],
183
+ globals: true,
184
+ },
204
185
  ```
205
186
 
206
- For now, `qwik-testing-library` needs to consider your project as a lib ([PR welcomed][prs] to simplify this).
207
- Hence, the `build.lib` section in the config above.
208
-
209
- As the build will try to use `./src/index.ts` as the entry point, we need to create it:
210
-
211
- ```ts
212
- // ./src/index.ts
213
-
214
- /**
215
- * DO NOT DELETE THIS FILE
216
- *
217
- * This entrypoint is needed by @noma.to/qwik-testing-library to run your tests
218
- */
219
- ```
220
-
221
- Then, create the `vitest.setup.ts` file:
222
-
223
- ```ts
224
- // vitest.setup.ts
225
-
226
- // Configure DOM matchers to work in Vitest
227
- import "@testing-library/jest-dom/vitest";
228
-
229
- // This has to run before qdev.ts loads. `beforeAll` is too late
230
- globalThis.qTest = false; // Forces Qwik to run as if it was in a Browser
231
- globalThis.qRuntimeQrl = true;
232
- globalThis.qDev = true;
233
- globalThis.qInspector = false;
234
- ```
235
-
236
- This setup will make sure that Qwik is properly configured.
237
- It also loads `@testing-library/jest-dom/vitest` in your test runner
238
- so you can use matchers like `expect(...).toBeInTheDocument()`.
187
+ The `@noma.to/qwik-testing-library/setup` module configures Qwik globals (`qTest`, `qRuntimeQrl`, `qDev`,
188
+ `qInspector`) for testing. It must run before any Qwik code loads, which is why it's added to `setupFiles`.
239
189
 
240
190
  By default, Qwik Testing Library cleans everything up automatically for you.
241
191
  You can opt out of this by setting the environment variable `QTL_SKIP_AUTO_CLEANUP` to `true`.
@@ -309,7 +259,7 @@ describe("<Counter />", () => {
309
259
  await user.click(incrementBtn);
310
260
 
311
261
  // assert that the counter is now 2
312
- await waitFor(() => expect(screen.findByText(/count:2/)).toBeInTheDocument());
262
+ expect(await screen.findByText(/count:2/)).toBeInTheDocument();
313
263
  });
314
264
  })
315
265
  ```
@@ -55,21 +55,17 @@ async function render(ui, options = {}) {
55
55
  baseElement = document.body;
56
56
  }
57
57
  if (!container) {
58
- container = baseElement.insertBefore(document.createElement("host"), baseElement.firstChild);
58
+ container = baseElement.insertBefore(
59
+ document.createElement("host"),
60
+ baseElement.firstChild
61
+ );
59
62
  }
60
- const wrappedUi = !Wrapper ? ui : /* @__PURE__ */ jsxRuntime.jsx(Wrapper, {
61
- children: ui
62
- });
63
+ const wrappedUi = !Wrapper ? ui : /* @__PURE__ */ jsxRuntime.jsx(Wrapper, { children: ui });
63
64
  const doc = baseElement.ownerDocument;
64
65
  const win = doc.defaultView;
65
66
  new Function("document", "window", server.getQwikLoaderScript())(doc, win);
66
- const { cleanup: cleanup2 } = await qwik.render(container, wrappedUi, {
67
- serverData
68
- });
69
- mountedContainers.add({
70
- container,
71
- componentCleanup: cleanup2
72
- });
67
+ const { cleanup: cleanup2 } = await qwik.render(container, wrappedUi, { serverData });
68
+ mountedContainers.add({ container, componentCleanup: cleanup2 });
73
69
  return {
74
70
  container,
75
71
  baseElement,
@@ -82,10 +78,9 @@ async function render(ui, options = {}) {
82
78
  return template.content;
83
79
  }
84
80
  },
85
- debug: (el = baseElement, maxLength, options2) => Array.isArray(el) ? el.forEach((e) => console.log(dom.prettyDOM(e, maxLength, options2))) : console.log(dom.prettyDOM(el, maxLength, {
86
- ...options2,
87
- filterNode: () => true
88
- })),
81
+ debug: (el = baseElement, maxLength, options2) => Array.isArray(el) ? el.forEach((e) => console.log(dom.prettyDOM(e, maxLength, options2))) : console.log(
82
+ dom.prettyDOM(el, maxLength, { ...options2, filterNode: () => true })
83
+ ),
89
84
  unmount: cleanup2,
90
85
  ...dom.getQueriesForElement(container, queries)
91
86
  };
@@ -32,21 +32,17 @@ async function render(ui, options = {}) {
32
32
  baseElement = document.body;
33
33
  }
34
34
  if (!container) {
35
- container = baseElement.insertBefore(document.createElement("host"), baseElement.firstChild);
35
+ container = baseElement.insertBefore(
36
+ document.createElement("host"),
37
+ baseElement.firstChild
38
+ );
36
39
  }
37
- const wrappedUi = !Wrapper ? ui : /* @__PURE__ */ jsx(Wrapper, {
38
- children: ui
39
- });
40
+ const wrappedUi = !Wrapper ? ui : /* @__PURE__ */ jsx(Wrapper, { children: ui });
40
41
  const doc = baseElement.ownerDocument;
41
42
  const win = doc.defaultView;
42
43
  new Function("document", "window", getQwikLoaderScript())(doc, win);
43
- const { cleanup: cleanup2 } = await qwik.render(container, wrappedUi, {
44
- serverData
45
- });
46
- mountedContainers.add({
47
- container,
48
- componentCleanup: cleanup2
49
- });
44
+ const { cleanup: cleanup2 } = await qwik.render(container, wrappedUi, { serverData });
45
+ mountedContainers.add({ container, componentCleanup: cleanup2 });
50
46
  return {
51
47
  container,
52
48
  baseElement,
@@ -59,10 +55,9 @@ async function render(ui, options = {}) {
59
55
  return template.content;
60
56
  }
61
57
  },
62
- debug: (el = baseElement, maxLength, options2) => Array.isArray(el) ? el.forEach((e) => console.log(prettyDOM(e, maxLength, options2))) : console.log(prettyDOM(el, maxLength, {
63
- ...options2,
64
- filterNode: () => true
65
- })),
58
+ debug: (el = baseElement, maxLength, options2) => Array.isArray(el) ? el.forEach((e) => console.log(prettyDOM(e, maxLength, options2))) : console.log(
59
+ prettyDOM(el, maxLength, { ...options2, filterNode: () => true })
60
+ ),
66
61
  unmount: cleanup2,
67
62
  ...getQueriesForElement(container, queries)
68
63
  };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ globalThis.qTest = false;
4
+ globalThis.qRuntimeQrl = true;
5
+ globalThis.qDev = true;
6
+ globalThis.qInspector = false;
7
+ const __qwikSetupComplete = true;
8
+ exports.__qwikSetupComplete = __qwikSetupComplete;
@@ -0,0 +1,8 @@
1
+ globalThis.qTest = false;
2
+ globalThis.qRuntimeQrl = true;
3
+ globalThis.qDev = true;
4
+ globalThis.qInspector = false;
5
+ const __qwikSetupComplete = true;
6
+ export {
7
+ __qwikSetupComplete
8
+ };
@@ -1,4 +1,4 @@
1
- import { JSXOutput } from "@builder.io/qwik";
1
+ import type { JSXOutput } from "@builder.io/qwik";
2
2
  import type { Options, Result } from "./types";
3
3
  declare function render(ui: JSXOutput, options?: Options): Promise<Result>;
4
4
  declare function cleanup(): void;
@@ -0,0 +1,7 @@
1
+ declare global {
2
+ var qTest: boolean;
3
+ var qRuntimeQrl: boolean;
4
+ var qDev: boolean;
5
+ var qInspector: boolean;
6
+ }
7
+ export declare const __qwikSetupComplete = true;
package/package.json CHANGED
@@ -1,18 +1,23 @@
1
1
  {
2
2
  "name": "@noma.to/qwik-testing-library",
3
- "version": "1.4.0",
3
+ "version": "1.5.1",
4
4
  "description": "Simple and complete Qwik testing utilities that encourage good testing practices.",
5
5
  "repository": "https://github.com/ianlet/qwik-testing-library",
6
6
  "homepage": "https://github.com/ianlet/qwik-testing-library",
7
7
  "license": "MIT",
8
8
  "main": "./lib/index.qwik.mjs",
9
- "qwik": "./lib/index.qwik.mjs",
10
9
  "types": "./lib-types/index.d.ts",
10
+ "qwik": "./lib/index.qwik.mjs",
11
11
  "exports": {
12
12
  ".": {
13
13
  "types": "./lib-types/index.d.ts",
14
14
  "import": "./lib/index.qwik.mjs",
15
15
  "require": "./lib/index.qwik.cjs"
16
+ },
17
+ "./setup": {
18
+ "types": "./lib-types/setup.d.ts",
19
+ "import": "./lib/setup.qwik.mjs",
20
+ "require": "./lib/setup.qwik.cjs"
16
21
  }
17
22
  },
18
23
  "files": [
@@ -35,17 +40,17 @@
35
40
  },
36
41
  "devDependencies": {
37
42
  "@types/eslint": "8.56.10",
38
- "@types/node": "24.5.0",
39
- "@typescript-eslint/eslint-plugin": "8.44.0",
40
- "@typescript-eslint/parser": "8.45.0",
43
+ "@types/node": "25.1.0",
44
+ "@typescript-eslint/eslint-plugin": "8.54.0",
45
+ "@typescript-eslint/parser": "8.54.0",
41
46
  "eslint": "8.57.1",
42
- "eslint-plugin-qwik": "1.16.0",
43
- "prettier": "3.6.2",
44
- "typescript": "5.9.2",
47
+ "eslint-plugin-qwik": "1.19.0",
48
+ "prettier": "3.8.1",
49
+ "typescript": "5.9.3",
45
50
  "undici": "*",
46
- "vite": "7.1.7",
47
- "vite-tsconfig-paths": "^5.1.4",
48
- "vitest": "^3.2.4"
51
+ "vite": "7.3.1",
52
+ "vite-tsconfig-paths": "^6.0.5",
53
+ "vitest": "^4.0.18"
49
54
  },
50
55
  "peerDependencies": {
51
56
  "@builder.io/qwik": ">= 1.12.0 < 2",