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

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.
Files changed (97) hide show
  1. package/README.md +18 -5
  2. package/lib/index.qwik.cjs +0 -4
  3. package/lib/index.qwik.mjs +0 -4
  4. package/lib/lib/qwik-testing-library.qwik.cjs +18 -6
  5. package/lib/lib/qwik-testing-library.qwik.mjs +18 -6
  6. package/lib-types/lib/qwik-testing-library.d.ts +1 -2
  7. package/package.json +9 -9
  8. package/lib/lib/mock.qwik.cjs +0 -14
  9. package/lib/lib/mock.qwik.mjs +0 -14
  10. package/lib/lib/qwikloader.qwik.cjs +0 -252
  11. package/lib/lib/qwikloader.qwik.mjs +0 -252
  12. package/lib/node_modules/.pnpm/@jridgewell_sourcemap-codec@1.5.0/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.qwik.cjs +0 -89
  13. package/lib/node_modules/.pnpm/@jridgewell_sourcemap-codec@1.5.0/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.qwik.mjs +0 -89
  14. package/lib/node_modules/.pnpm/@vitest_expect@3.0.5/node_modules/@vitest/expect/dist/index.qwik.cjs +0 -2191
  15. package/lib/node_modules/.pnpm/@vitest_expect@3.0.5/node_modules/@vitest/expect/dist/index.qwik.mjs +0 -2191
  16. package/lib/node_modules/.pnpm/@vitest_pretty-format@3.0.5/node_modules/@vitest/pretty-format/dist/index.qwik.cjs +0 -1499
  17. package/lib/node_modules/.pnpm/@vitest_pretty-format@3.0.5/node_modules/@vitest/pretty-format/dist/index.qwik.mjs +0 -1499
  18. package/lib/node_modules/.pnpm/@vitest_runner@3.0.5/node_modules/@vitest/runner/dist/chunk-tasks.qwik.cjs +0 -44
  19. package/lib/node_modules/.pnpm/@vitest_runner@3.0.5/node_modules/@vitest/runner/dist/chunk-tasks.qwik.mjs +0 -44
  20. package/lib/node_modules/.pnpm/@vitest_runner@3.0.5/node_modules/@vitest/runner/dist/index.qwik.cjs +0 -757
  21. package/lib/node_modules/.pnpm/@vitest_runner@3.0.5/node_modules/@vitest/runner/dist/index.qwik.mjs +0 -757
  22. package/lib/node_modules/.pnpm/@vitest_snapshot@3.0.5/node_modules/@vitest/snapshot/dist/index.qwik.cjs +0 -2079
  23. package/lib/node_modules/.pnpm/@vitest_snapshot@3.0.5/node_modules/@vitest/snapshot/dist/index.qwik.mjs +0 -2079
  24. package/lib/node_modules/.pnpm/@vitest_spy@3.0.5/node_modules/@vitest/spy/dist/index.qwik.cjs +0 -165
  25. package/lib/node_modules/.pnpm/@vitest_spy@3.0.5/node_modules/@vitest/spy/dist/index.qwik.mjs +0 -165
  26. package/lib/node_modules/.pnpm/@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/chunk-_commonjsHelpers.qwik.cjs +0 -162
  27. package/lib/node_modules/.pnpm/@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/chunk-_commonjsHelpers.qwik.mjs +0 -162
  28. package/lib/node_modules/.pnpm/@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/diff.qwik.cjs +0 -1755
  29. package/lib/node_modules/.pnpm/@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/diff.qwik.mjs +0 -1755
  30. package/lib/node_modules/.pnpm/@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/error.qwik.cjs +0 -137
  31. package/lib/node_modules/.pnpm/@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/error.qwik.mjs +0 -137
  32. package/lib/node_modules/.pnpm/@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/helpers.qwik.cjs +0 -150
  33. package/lib/node_modules/.pnpm/@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/helpers.qwik.mjs +0 -150
  34. package/lib/node_modules/.pnpm/@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/index.qwik.cjs +0 -474
  35. package/lib/node_modules/.pnpm/@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/index.qwik.mjs +0 -474
  36. package/lib/node_modules/.pnpm/@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/source-map.qwik.cjs +0 -216
  37. package/lib/node_modules/.pnpm/@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/source-map.qwik.mjs +0 -216
  38. package/lib/node_modules/.pnpm/chai@5.1.2/node_modules/chai/chai.qwik.cjs +0 -3937
  39. package/lib/node_modules/.pnpm/chai@5.1.2/node_modules/chai/chai.qwik.mjs +0 -3937
  40. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/arguments.qwik.cjs +0 -9
  41. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/arguments.qwik.mjs +0 -10
  42. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/array.qwik.cjs +0 -16
  43. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/array.qwik.mjs +0 -17
  44. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/bigint.qwik.cjs +0 -9
  45. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/bigint.qwik.mjs +0 -10
  46. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/class.qwik.cjs +0 -16
  47. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/class.qwik.mjs +0 -17
  48. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/date.qwik.cjs +0 -12
  49. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/date.qwik.mjs +0 -13
  50. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/error.qwik.cjs +0 -36
  51. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/error.qwik.mjs +0 -37
  52. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/function.qwik.cjs +0 -11
  53. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/function.qwik.mjs +0 -12
  54. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/helpers.qwik.cjs +0 -160
  55. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/helpers.qwik.mjs +0 -160
  56. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/html.qwik.cjs +0 -36
  57. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/html.qwik.mjs +0 -36
  58. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/index.qwik.cjs +0 -130
  59. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/index.qwik.mjs +0 -130
  60. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/map.qwik.cjs +0 -23
  61. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/map.qwik.mjs +0 -24
  62. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/number.qwik.cjs +0 -19
  63. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/number.qwik.mjs +0 -20
  64. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/object.qwik.cjs +0 -24
  65. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/object.qwik.mjs +0 -25
  66. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/promise.qwik.cjs +0 -17
  67. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/promise.qwik.mjs +0 -18
  68. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/regexp.qwik.cjs +0 -9
  69. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/regexp.qwik.mjs +0 -10
  70. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/set.qwik.cjs +0 -16
  71. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/set.qwik.mjs +0 -17
  72. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/string.qwik.cjs +0 -23
  73. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/string.qwik.mjs +0 -24
  74. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/symbol.qwik.cjs +0 -8
  75. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/symbol.qwik.mjs +0 -9
  76. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/typedarray.qwik.cjs +0 -34
  77. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/typedarray.qwik.mjs +0 -35
  78. package/lib/node_modules/.pnpm/magic-string@0.30.17/node_modules/magic-string/dist/magic-string.es.qwik.cjs +0 -979
  79. package/lib/node_modules/.pnpm/magic-string@0.30.17/node_modules/magic-string/dist/magic-string.es.qwik.mjs +0 -979
  80. package/lib/node_modules/.pnpm/pathe@2.0.2/node_modules/pathe/dist/shared/pathe.UZ-hd4nF.qwik.cjs +0 -101
  81. package/lib/node_modules/.pnpm/pathe@2.0.2/node_modules/pathe/dist/shared/pathe.UZ-hd4nF.qwik.mjs +0 -101
  82. package/lib/node_modules/.pnpm/tinyrainbow@2.0.0/node_modules/tinyrainbow/dist/browser.qwik.cjs +0 -4
  83. package/lib/node_modules/.pnpm/tinyrainbow@2.0.0/node_modules/tinyrainbow/dist/browser.qwik.mjs +0 -5
  84. package/lib/node_modules/.pnpm/tinyrainbow@2.0.0/node_modules/tinyrainbow/dist/chunk-BVHSVHOK.qwik.cjs +0 -80
  85. package/lib/node_modules/.pnpm/tinyrainbow@2.0.0/node_modules/tinyrainbow/dist/chunk-BVHSVHOK.qwik.mjs +0 -80
  86. package/lib/node_modules/.pnpm/tinyspy@3.0.2/node_modules/tinyspy/dist/index.qwik.cjs +0 -104
  87. package/lib/node_modules/.pnpm/tinyspy@3.0.2/node_modules/tinyspy/dist/index.qwik.mjs +0 -104
  88. package/lib/node_modules/.pnpm/vitest@3.0.5_@types_node@22.13.1_@vitest_ui@3.0.5_jiti@2.4.2_jsdom@26.0.0/node_modules/vitest/dist/chunks/_commonjsHelpers.BFTU3MAI.qwik.cjs +0 -8
  89. package/lib/node_modules/.pnpm/vitest@3.0.5_@types_node@22.13.1_@vitest_ui@3.0.5_jiti@2.4.2_jsdom@26.0.0/node_modules/vitest/dist/chunks/_commonjsHelpers.BFTU3MAI.qwik.mjs +0 -8
  90. package/lib/node_modules/.pnpm/vitest@3.0.5_@types_node@22.13.1_@vitest_ui@3.0.5_jiti@2.4.2_jsdom@26.0.0/node_modules/vitest/dist/chunks/date.W2xKR2qe.qwik.cjs +0 -56
  91. package/lib/node_modules/.pnpm/vitest@3.0.5_@types_node@22.13.1_@vitest_ui@3.0.5_jiti@2.4.2_jsdom@26.0.0/node_modules/vitest/dist/chunks/date.W2xKR2qe.qwik.mjs +0 -56
  92. package/lib/node_modules/.pnpm/vitest@3.0.5_@types_node@22.13.1_@vitest_ui@3.0.5_jiti@2.4.2_jsdom@26.0.0/node_modules/vitest/dist/chunks/utils.C8RiOc4B.qwik.cjs +0 -66
  93. package/lib/node_modules/.pnpm/vitest@3.0.5_@types_node@22.13.1_@vitest_ui@3.0.5_jiti@2.4.2_jsdom@26.0.0/node_modules/vitest/dist/chunks/utils.C8RiOc4B.qwik.mjs +0 -66
  94. package/lib/node_modules/.pnpm/vitest@3.0.5_@types_node@22.13.1_@vitest_ui@3.0.5_jiti@2.4.2_jsdom@26.0.0/node_modules/vitest/dist/chunks/vi.CjhMlMwf.qwik.cjs +0 -2977
  95. package/lib/node_modules/.pnpm/vitest@3.0.5_@types_node@22.13.1_@vitest_ui@3.0.5_jiti@2.4.2_jsdom@26.0.0/node_modules/vitest/dist/chunks/vi.CjhMlMwf.qwik.mjs +0 -2977
  96. package/lib-types/lib/mock.d.ts +0 -34
  97. package/lib-types/lib/qwikloader.d.ts +0 -1
package/README.md CHANGED
@@ -19,7 +19,7 @@ src="https://raw.githubusercontent.com/ianlet/qwik-testing-library/main/high-vol
19
19
  [![MIT License][license-badge]][license]
20
20
 
21
21
  <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
22
- [![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square)](#contributors-)
22
+ [![All Contributors](https://img.shields.io/badge/all_contributors-3-orange.svg?style=flat-square)](#contributors-)
23
23
  <!-- ALL-CONTRIBUTORS-BADGE:END -->
24
24
  [![PRs Welcome][prs-badge]][prs]
25
25
  [![Code of Conduct][coc-badge]][coc]
@@ -141,10 +141,12 @@ npm install --save-dev @testing-library/jest-dom @testing-library/user-event
141
141
  ```
142
142
 
143
143
  Finally, we need a DOM environment to run the tests in.
144
- This library was tested (for now) only with `jsdom` so we recommend using it:
144
+ This library is tested with both `jsdom` and `happy-dom`:
145
145
 
146
146
  ```shell
147
147
  npm install --save-dev jsdom
148
+ # or
149
+ npm install --save-dev happy-dom
148
150
  ```
149
151
 
150
152
  [npm]: https://www.npmjs.com/
@@ -192,7 +194,7 @@ export default defineConfig((configEnv) =>
192
194
  },
193
195
  // configure your test environment
194
196
  test: {
195
- environment: "jsdom",
197
+ environment: "jsdom", // or "happy-dom"
196
198
  setupFiles: ["./vitest.setup.ts"],
197
199
  globals: true,
198
200
  },
@@ -318,17 +320,27 @@ describe("<Counter />", () => {
318
320
  > This feature is under a testing phase and thus experimental.
319
321
  > Its API may change in the future, so use it at your own risk.
320
322
 
321
- The Qwik Testing Library provides a `mock$` function
323
+ #### Setup
324
+
325
+ Optionally, you can install `@noma.to/qwik-mock` to mock callbacks of Qwik components. It provides a `mock$` function
322
326
  that can be used to create a mock of a QRL and verify interactions on your Qwik components.
323
327
 
328
+ ```shell
329
+ npm install --save-dev @noma.to/qwik-mock
330
+ ```
331
+
324
332
  It is _not_ a replacement of regular mocking functions (such as `vi.fn` and `vi.mock`) as its intended use is only for
325
333
  testing callbacks of Qwik components.
326
334
 
335
+ #### Usage
336
+
327
337
  Here's an example on how to use the `mock$` function:
328
338
 
329
339
  ```tsx title="counter.spec.tsx"
330
340
  // import qwik-testing methods
331
- import {mock$, clearAllMock, render, screen, waitFor} from "@noma.to/qwik-testing-library";
341
+ import {render, screen, waitFor} from "@noma.to/qwik-testing-library";
342
+ // import qwik-mock methods
343
+ import {mock$, clearAllMock} from "@noma.to/qwik-mock";
332
344
  // import the userEvent methods to interact with the DOM
333
345
  import {userEvent} from "@testing-library/user-event";
334
346
 
@@ -472,6 +484,7 @@ Thanks goes to these people ([emoji key][emojis]):
472
484
  <tr>
473
485
  <td align="center" valign="top" width="14.28%"><a href="https://noma.to/"><img src="https://avatars.githubusercontent.com/u/6018732?v=4?s=100" width="100px;" alt="Ian Létourneau"/><br /><sub><b>Ian Létourneau</b></sub></a><br /><a href="https://github.com/ianlet/qwik-testing-library/commits?author=ianlet" title="Code">💻</a> <a href="https://github.com/ianlet/qwik-testing-library/commits?author=ianlet" title="Tests">⚠️</a> <a href="#ideas-ianlet" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/ianlet/qwik-testing-library/commits?author=ianlet" title="Documentation">📖</a> <a href="#example-ianlet" title="Examples">💡</a></td>
474
486
  <td align="center" valign="top" width="14.28%"><a href="https://brandonpittman.com"><img src="https://avatars.githubusercontent.com/u/967145?v=4?s=100" width="100px;" alt="Brandon Pittman"/><br /><sub><b>Brandon Pittman</b></sub></a><br /><a href="https://github.com/ianlet/qwik-testing-library/commits?author=brandonpittman" title="Documentation">📖</a></td>
487
+ <td align="center" valign="top" width="14.28%"><a href="http://jackshelton.com"><img src="https://avatars.githubusercontent.com/u/104264123?v=4?s=100" width="100px;" alt="Jack Shelton"/><br /><sub><b>Jack Shelton</b></sub></a><br /><a href="https://github.com/ianlet/qwik-testing-library/pulls?q=is%3Apr+reviewed-by%3Athejackshelton" title="Reviewed Pull Requests">👀</a></td>
475
488
  </tr>
476
489
  </tbody>
477
490
  <tfoot>
@@ -2,12 +2,8 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const qwikTestingLibrary = require("./lib/qwik-testing-library.qwik.cjs");
4
4
  const dom = require("@testing-library/dom");
5
- const mock = require("./lib/mock.qwik.cjs");
6
5
  exports.cleanup = qwikTestingLibrary.cleanup;
7
6
  exports.render = qwikTestingLibrary.render;
8
- exports.clearAllMocks = mock.clearAllMocks;
9
- exports.mock$ = mock.mock$;
10
- exports.mockQrl = mock.mockQrl;
11
7
  Object.keys(dom).forEach((k) => {
12
8
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
13
9
  enumerable: true,
@@ -1,10 +1,6 @@
1
1
  import { cleanup, render } from "./lib/qwik-testing-library.qwik.mjs";
2
2
  export * from "@testing-library/dom";
3
- import { clearAllMocks, mock$, mockQrl } from "./lib/mock.qwik.mjs";
4
3
  export {
5
4
  cleanup,
6
- clearAllMocks,
7
- mock$,
8
- mockQrl,
9
5
  render
10
6
  };
@@ -24,8 +24,21 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
25
25
  const jsxRuntime = require("@builder.io/qwik/jsx-runtime");
26
26
  const dom = require("@testing-library/dom");
27
- const mock = require("./mock.qwik.cjs");
28
- const qwikloader = require("./qwikloader.qwik.cjs");
27
+ const server = require("@builder.io/qwik/server");
28
+ if (typeof HTMLTemplateElement !== "undefined") {
29
+ const testTemplate = document.createElement("template");
30
+ const testNode = document.createComment("test");
31
+ testTemplate.insertBefore(testNode, null);
32
+ const needsPatch = testTemplate.childNodes.length === 0;
33
+ testNode.remove();
34
+ if (needsPatch) {
35
+ Object.defineProperty(HTMLTemplateElement.prototype, "childNodes", {
36
+ get() {
37
+ return this.content.childNodes;
38
+ }
39
+ });
40
+ }
41
+ }
29
42
  if (typeof process === "undefined" || !process.env?.QTL_SKIP_AUTO_CLEANUP) {
30
43
  if (typeof afterEach === "function") {
31
44
  afterEach(() => {
@@ -47,7 +60,9 @@ async function render(ui, options = {}) {
47
60
  const wrappedUi = !Wrapper ? ui : /* @__PURE__ */ jsxRuntime.jsx(Wrapper, {
48
61
  children: ui
49
62
  });
50
- qwikloader.qwikLoader(baseElement.ownerDocument);
63
+ const doc = baseElement.ownerDocument;
64
+ const win = doc.defaultView;
65
+ new Function("document", "window", server.getQwikLoaderScript())(doc, win);
51
66
  const { cleanup: cleanup2 } = await qwik.render(container, wrappedUi, {
52
67
  serverData
53
68
  });
@@ -86,9 +101,6 @@ function cleanupAtContainer(ref) {
86
101
  function cleanup() {
87
102
  mountedContainers.forEach(cleanupAtContainer);
88
103
  }
89
- exports.clearAllMocks = mock.clearAllMocks;
90
- exports.mock$ = mock.mock$;
91
- exports.mockQrl = mock.mockQrl;
92
104
  exports.cleanup = cleanup;
93
105
  exports.render = render;
94
106
  Object.keys(dom).forEach((k) => {
@@ -1,8 +1,21 @@
1
1
  import { jsx } from "@builder.io/qwik/jsx-runtime";
2
2
  import { getQueriesForElement, prettyDOM } from "@testing-library/dom";
3
3
  export * from "@testing-library/dom";
4
- import { clearAllMocks, mock$, mockQrl } from "./mock.qwik.mjs";
5
- import { qwikLoader } from "./qwikloader.qwik.mjs";
4
+ import { getQwikLoaderScript } from "@builder.io/qwik/server";
5
+ if (typeof HTMLTemplateElement !== "undefined") {
6
+ const testTemplate = document.createElement("template");
7
+ const testNode = document.createComment("test");
8
+ testTemplate.insertBefore(testNode, null);
9
+ const needsPatch = testTemplate.childNodes.length === 0;
10
+ testNode.remove();
11
+ if (needsPatch) {
12
+ Object.defineProperty(HTMLTemplateElement.prototype, "childNodes", {
13
+ get() {
14
+ return this.content.childNodes;
15
+ }
16
+ });
17
+ }
18
+ }
6
19
  if (typeof process === "undefined" || !process.env?.QTL_SKIP_AUTO_CLEANUP) {
7
20
  if (typeof afterEach === "function") {
8
21
  afterEach(() => {
@@ -24,7 +37,9 @@ async function render(ui, options = {}) {
24
37
  const wrappedUi = !Wrapper ? ui : /* @__PURE__ */ jsx(Wrapper, {
25
38
  children: ui
26
39
  });
27
- qwikLoader(baseElement.ownerDocument);
40
+ const doc = baseElement.ownerDocument;
41
+ const win = doc.defaultView;
42
+ new Function("document", "window", getQwikLoaderScript())(doc, win);
28
43
  const { cleanup: cleanup2 } = await qwik.render(container, wrappedUi, {
29
44
  serverData
30
45
  });
@@ -65,8 +80,5 @@ function cleanup() {
65
80
  }
66
81
  export {
67
82
  cleanup,
68
- clearAllMocks,
69
- mock$,
70
- mockQrl,
71
83
  render
72
84
  };
@@ -1,7 +1,6 @@
1
1
  import { JSXOutput } from "@builder.io/qwik";
2
2
  import type { Options, Result } from "./types";
3
- import { clearAllMocks, mock$, mockQrl } from "./mock";
4
3
  declare function render(ui: JSXOutput, options?: Options): Promise<Result>;
5
4
  declare function cleanup(): void;
6
5
  export * from "@testing-library/dom";
7
- export { cleanup, render, mock$, mockQrl, clearAllMocks };
6
+ export { cleanup, render };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noma.to/qwik-testing-library",
3
- "version": "1.3.1",
3
+ "version": "1.4.0",
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",
@@ -35,17 +35,17 @@
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/eslint": "8.56.10",
38
- "@types/node": "22.13.1",
39
- "@typescript-eslint/eslint-plugin": "8.24.0",
40
- "@typescript-eslint/parser": "8.24.0",
38
+ "@types/node": "24.5.0",
39
+ "@typescript-eslint/eslint-plugin": "8.44.0",
40
+ "@typescript-eslint/parser": "8.45.0",
41
41
  "eslint": "8.57.1",
42
- "eslint-plugin-qwik": "1.12.0",
43
- "prettier": "3.5.0",
44
- "typescript": "5.7.3",
42
+ "eslint-plugin-qwik": "1.16.0",
43
+ "prettier": "3.6.2",
44
+ "typescript": "5.9.2",
45
45
  "undici": "*",
46
- "vite": "6.1.0",
46
+ "vite": "7.1.7",
47
47
  "vite-tsconfig-paths": "^5.1.4",
48
- "vitest": "^3.0.5"
48
+ "vitest": "^3.2.4"
49
49
  },
50
50
  "peerDependencies": {
51
51
  "@builder.io/qwik": ">= 1.12.0 < 2",
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const qwik = require("@builder.io/qwik");
4
- const vi_CjhMlMwf = require("../node_modules/.pnpm/vitest@3.0.5_@types_node@22.13.1_@vitest_ui@3.0.5_jiti@2.4.2_jsdom@26.0.0/node_modules/vitest/dist/chunks/vi.CjhMlMwf.qwik.cjs");
5
- const mockQrl = () => {
6
- return qwik.$(vi_CjhMlMwf.v.fn());
7
- };
8
- const mock$ = qwik.implicit$FirstArg(mockQrl);
9
- function clearAllMocks() {
10
- vi_CjhMlMwf.v.clearAllMocks();
11
- }
12
- exports.clearAllMocks = clearAllMocks;
13
- exports.mock$ = mock$;
14
- exports.mockQrl = mockQrl;
@@ -1,14 +0,0 @@
1
- import { implicit$FirstArg, $ } from "@builder.io/qwik";
2
- import { v as vi } from "../node_modules/.pnpm/vitest@3.0.5_@types_node@22.13.1_@vitest_ui@3.0.5_jiti@2.4.2_jsdom@26.0.0/node_modules/vitest/dist/chunks/vi.CjhMlMwf.qwik.mjs";
3
- const mockQrl = () => {
4
- return $(vi.fn());
5
- };
6
- const mock$ = implicit$FirstArg(mockQrl);
7
- function clearAllMocks() {
8
- vi.clearAllMocks();
9
- }
10
- export {
11
- clearAllMocks,
12
- mock$,
13
- mockQrl
14
- };
@@ -1,252 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
8
- enumerable: true,
9
- configurable: true,
10
- writable: true,
11
- value
12
- }) : obj[key] = value;
13
- var __spreadValues = (a, b) => {
14
- for (var prop in b || (b = {})) {
15
- __hasOwnProp.call(b, prop) && __defNormalProp(a, prop, b[prop]);
16
- }
17
- if (__getOwnPropSymbols) {
18
- for (var prop of __getOwnPropSymbols(b)) {
19
- __propIsEnum.call(b, prop) && __defNormalProp(a, prop, b[prop]);
20
- }
21
- }
22
- return a;
23
- };
24
- var qwikLoader = (doc, hasInitialized) => {
25
- const Q_CONTEXT = "__q_context__";
26
- const win = window;
27
- const events = /* @__PURE__ */ new Set();
28
- const roots = /* @__PURE__ */ new Set([doc]);
29
- const nativeQuerySelectorAll = (root, selector) => Array.from(root.querySelectorAll(selector));
30
- const querySelectorAll = (query) => {
31
- const elements = [];
32
- roots.forEach(
33
- (root) => elements.push(...nativeQuerySelectorAll(root, query))
34
- );
35
- return elements;
36
- };
37
- const findShadowRoots = (fragment) => {
38
- processEventOrNode(fragment);
39
- nativeQuerySelectorAll(fragment, "[q\\:shadowroot]").forEach((parent) => {
40
- const shadowRoot = parent.shadowRoot;
41
- shadowRoot && findShadowRoots(shadowRoot);
42
- });
43
- };
44
- const isPromise = (promise) => promise && "function" == typeof promise.then;
45
- const broadcast = (infix, ev, type = ev.type) => {
46
- querySelectorAll("[on" + infix + "\\:" + type + "]").forEach(
47
- (el) => dispatch(el, infix, ev, type)
48
- );
49
- };
50
- const resolveContainer = (containerEl) => {
51
- if (void 0 === containerEl._qwikjson_) {
52
- let script = (containerEl === doc.documentElement ? doc.body : containerEl).lastElementChild;
53
- while (script) {
54
- if ("SCRIPT" === script.tagName && "qwik/json" === script.getAttribute("type")) {
55
- containerEl._qwikjson_ = JSON.parse(
56
- script.textContent.replace(/\\x3C(\/?script)/gi, "<$1")
57
- );
58
- break;
59
- }
60
- script = script.previousElementSibling;
61
- }
62
- }
63
- };
64
- const createEvent = (eventName, detail) => new CustomEvent(eventName, {
65
- detail
66
- });
67
- const dispatch = async (element, onPrefix, ev, eventName = ev.type) => {
68
- const attrName = "on" + onPrefix + ":" + eventName;
69
- element.hasAttribute("preventdefault:" + eventName) && ev.preventDefault();
70
- const ctx = element._qc_;
71
- const relevantListeners = ctx && ctx.li.filter((li) => li[0] === attrName);
72
- if (relevantListeners && relevantListeners.length > 0) {
73
- for (const listener of relevantListeners) {
74
- const results = listener[1].getFn(
75
- [element, ev],
76
- () => element.isConnected
77
- )(ev, element);
78
- const cancelBubble = ev.cancelBubble;
79
- isPromise(results) && await results;
80
- cancelBubble && ev.stopPropagation();
81
- }
82
- return;
83
- }
84
- const attrValue = element.getAttribute(attrName);
85
- if (attrValue) {
86
- const container = element.closest("[q\\:container]");
87
- const qBase = container.getAttribute("q:base");
88
- const qVersion = container.getAttribute("q:version") || "unknown";
89
- const qManifest = container.getAttribute("q:manifest-hash") || "dev";
90
- const base = new URL(qBase, doc.baseURI);
91
- for (const qrl of attrValue.split("\n")) {
92
- const url = new URL(qrl, base);
93
- const href = url.href;
94
- const symbol = url.hash.replace(/^#?([^?[|]*).*$/, "$1") || "default";
95
- const reqTime = performance.now();
96
- let handler;
97
- let importError;
98
- let error;
99
- const isSync = qrl.startsWith("#");
100
- const eventData = {
101
- qBase,
102
- qManifest,
103
- qVersion,
104
- href,
105
- symbol,
106
- element,
107
- reqTime
108
- };
109
- if (isSync) {
110
- const hash = container.getAttribute("q:instance");
111
- handler = (doc["qFuncs_" + hash] || [])[Number.parseInt(symbol)];
112
- if (!handler) {
113
- importError = "sync";
114
- error = new Error("sync handler error for symbol: " + symbol);
115
- }
116
- } else {
117
- const uri = url.href.split("#")[0];
118
- try {
119
- const module2 = import(uri);
120
- resolveContainer(container);
121
- handler = (await module2)[symbol];
122
- if (!handler) {
123
- importError = "no-symbol";
124
- error = new Error(`${symbol} not in ${uri}`);
125
- }
126
- } catch (err) {
127
- importError || (importError = "async");
128
- error = err;
129
- }
130
- }
131
- if (!handler) {
132
- emitEvent(
133
- "qerror",
134
- __spreadValues(
135
- {
136
- importError,
137
- error
138
- },
139
- eventData
140
- )
141
- );
142
- console.error(error);
143
- break;
144
- }
145
- const previousCtx = doc[Q_CONTEXT];
146
- if (element.isConnected) {
147
- try {
148
- doc[Q_CONTEXT] = [element, ev, url];
149
- isSync || emitEvent("qsymbol", __spreadValues({}, eventData));
150
- const results = handler(ev, element);
151
- isPromise(results) && await results;
152
- } catch (error2) {
153
- emitEvent(
154
- "qerror",
155
- __spreadValues(
156
- {
157
- error: error2
158
- },
159
- eventData
160
- )
161
- );
162
- } finally {
163
- doc[Q_CONTEXT] = previousCtx;
164
- }
165
- }
166
- }
167
- }
168
- };
169
- const emitEvent = (eventName, detail) => {
170
- doc.dispatchEvent(createEvent(eventName, detail));
171
- };
172
- const camelToKebab = (str) => str.replace(/([A-Z])/g, (a) => "-" + a.toLowerCase());
173
- const processDocumentEvent = async (ev) => {
174
- let type = camelToKebab(ev.type);
175
- let element = ev.target;
176
- broadcast("-document", ev, type);
177
- while (element && element.getAttribute) {
178
- const results = dispatch(element, "", ev, type);
179
- let cancelBubble = ev.cancelBubble;
180
- isPromise(results) && await results;
181
- cancelBubble = cancelBubble || ev.cancelBubble || element.hasAttribute("stoppropagation:" + ev.type);
182
- element = ev.bubbles && true !== cancelBubble ? element.parentElement : null;
183
- }
184
- };
185
- const processWindowEvent = (ev) => {
186
- broadcast("-window", ev, camelToKebab(ev.type));
187
- };
188
- const processReadyStateChange = () => {
189
- var _a;
190
- const readyState = doc.readyState;
191
- if (!hasInitialized && ("interactive" == readyState || "complete" == readyState)) {
192
- roots.forEach(findShadowRoots);
193
- hasInitialized = 1;
194
- emitEvent("qinit");
195
- (null != (_a = win.requestIdleCallback) ? _a : win.setTimeout).bind(win)(
196
- () => emitEvent("qidle")
197
- );
198
- if (events.has("qvisible")) {
199
- const results = querySelectorAll("[on\\:qvisible]");
200
- const observer = new IntersectionObserver((entries) => {
201
- for (const entry of entries) {
202
- if (entry.isIntersecting) {
203
- observer.unobserve(entry.target);
204
- dispatch(entry.target, "", createEvent("qvisible", entry));
205
- }
206
- }
207
- });
208
- results.forEach((el) => observer.observe(el));
209
- }
210
- }
211
- };
212
- const addEventListener = (el, eventName, handler, capture = false) => el.addEventListener(eventName, handler, {
213
- capture,
214
- passive: false
215
- });
216
- const processEventOrNode = (...eventNames) => {
217
- for (const eventNameOrNode of eventNames) {
218
- if ("string" == typeof eventNameOrNode) {
219
- if (!events.has(eventNameOrNode)) {
220
- roots.forEach(
221
- (root) => addEventListener(root, eventNameOrNode, processDocumentEvent, true)
222
- );
223
- addEventListener(win, eventNameOrNode, processWindowEvent, true);
224
- events.add(eventNameOrNode);
225
- }
226
- } else if (!roots.has(eventNameOrNode)) {
227
- events.forEach(
228
- (eventName) => addEventListener(
229
- eventNameOrNode,
230
- eventName,
231
- processDocumentEvent,
232
- true
233
- )
234
- );
235
- roots.add(eventNameOrNode);
236
- }
237
- }
238
- };
239
- if (!(Q_CONTEXT in doc)) {
240
- doc[Q_CONTEXT] = 0;
241
- const qwikevents = win.qwikevents;
242
- Array.isArray(qwikevents) && processEventOrNode(...qwikevents);
243
- win.qwikevents = {
244
- events,
245
- roots,
246
- push: processEventOrNode
247
- };
248
- addEventListener(doc, "readystatechange", processReadyStateChange);
249
- processReadyStateChange();
250
- }
251
- };
252
- exports.qwikLoader = qwikLoader;