@noma.to/qwik-mock 1.0.2 → 1.1.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.
Files changed (53) hide show
  1. package/lib/lib/qwik-mock.cjs +24 -6
  2. package/lib/lib/qwik-mock.mjs +24 -6
  3. package/lib-types/index.d.ts +2 -1
  4. package/lib-types/lib/qwik-mock.d.ts +21 -19
  5. package/package.json +7 -6
  6. package/lib/node_modules/.pnpm/@jridgewell_sourcemap-codec@1.5.5/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.cjs +0 -83
  7. package/lib/node_modules/.pnpm/@jridgewell_sourcemap-codec@1.5.5/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs +0 -83
  8. package/lib/node_modules/.pnpm/@vitest_expect@4.0.18/node_modules/@vitest/expect/dist/index.cjs +0 -1785
  9. package/lib/node_modules/.pnpm/@vitest_expect@4.0.18/node_modules/@vitest/expect/dist/index.mjs +0 -1785
  10. package/lib/node_modules/.pnpm/@vitest_pretty-format@4.0.18/node_modules/@vitest/pretty-format/dist/index.cjs +0 -964
  11. package/lib/node_modules/.pnpm/@vitest_pretty-format@4.0.18/node_modules/@vitest/pretty-format/dist/index.mjs +0 -964
  12. package/lib/node_modules/.pnpm/@vitest_runner@4.0.18/node_modules/@vitest/runner/dist/chunk-tasks.cjs +0 -60
  13. package/lib/node_modules/.pnpm/@vitest_runner@4.0.18/node_modules/@vitest/runner/dist/chunk-tasks.mjs +0 -60
  14. package/lib/node_modules/.pnpm/@vitest_runner@4.0.18/node_modules/@vitest/runner/dist/index.cjs +0 -1102
  15. package/lib/node_modules/.pnpm/@vitest_runner@4.0.18/node_modules/@vitest/runner/dist/index.mjs +0 -1102
  16. package/lib/node_modules/.pnpm/@vitest_snapshot@4.0.18/node_modules/@vitest/snapshot/dist/index.cjs +0 -1289
  17. package/lib/node_modules/.pnpm/@vitest_snapshot@4.0.18/node_modules/@vitest/snapshot/dist/index.mjs +0 -1289
  18. package/lib/node_modules/.pnpm/@vitest_spy@4.0.18/node_modules/@vitest/spy/dist/index.cjs +0 -422
  19. package/lib/node_modules/.pnpm/@vitest_spy@4.0.18/node_modules/@vitest/spy/dist/index.mjs +0 -422
  20. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/chunk-_commonjsHelpers.cjs +0 -6
  21. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/chunk-_commonjsHelpers.mjs +0 -6
  22. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/chunk-pathe.M-eThtNZ.cjs +0 -98
  23. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/chunk-pathe.M-eThtNZ.mjs +0 -98
  24. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/diff.cjs +0 -1626
  25. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/diff.mjs +0 -1626
  26. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/display.cjs +0 -690
  27. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/display.mjs +0 -690
  28. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/error.cjs +0 -39
  29. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/error.mjs +0 -39
  30. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/helpers.cjs +0 -151
  31. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/helpers.mjs +0 -151
  32. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/serialize.cjs +0 -114
  33. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/serialize.mjs +0 -114
  34. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/source-map.cjs +0 -125
  35. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/source-map.mjs +0 -125
  36. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/timers.cjs +0 -22
  37. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/timers.mjs +0 -22
  38. package/lib/node_modules/.pnpm/chai@6.2.2/node_modules/chai/index.cjs +0 -4056
  39. package/lib/node_modules/.pnpm/chai@6.2.2/node_modules/chai/index.mjs +0 -4056
  40. package/lib/node_modules/.pnpm/magic-string@0.30.21/node_modules/magic-string/dist/magic-string.es.cjs +0 -994
  41. package/lib/node_modules/.pnpm/magic-string@0.30.21/node_modules/magic-string/dist/magic-string.es.mjs +0 -994
  42. package/lib/node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.cjs +0 -101
  43. package/lib/node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs +0 -101
  44. package/lib/node_modules/.pnpm/tinyrainbow@3.0.3/node_modules/tinyrainbow/dist/index.cjs +0 -84
  45. package/lib/node_modules/.pnpm/tinyrainbow@3.0.3/node_modules/tinyrainbow/dist/index.mjs +0 -84
  46. package/lib/node_modules/.pnpm/vitest@4.0.18_@types_node@25.1.0_@vitest_ui@4.0.18_happy-dom@20.0.11_jiti@2.4.2_jsdom@26.1.0__pd2l5poczrcnqygjcqiguyknnm/node_modules/vitest/dist/chunks/_commonjsHelpers.D26ty3Ew.cjs +0 -4
  47. package/lib/node_modules/.pnpm/vitest@4.0.18_@types_node@25.1.0_@vitest_ui@4.0.18_happy-dom@20.0.11_jiti@2.4.2_jsdom@26.1.0__pd2l5poczrcnqygjcqiguyknnm/node_modules/vitest/dist/chunks/_commonjsHelpers.D26ty3Ew.mjs +0 -4
  48. package/lib/node_modules/.pnpm/vitest@4.0.18_@types_node@25.1.0_@vitest_ui@4.0.18_happy-dom@20.0.11_jiti@2.4.2_jsdom@26.1.0__pd2l5poczrcnqygjcqiguyknnm/node_modules/vitest/dist/chunks/date.Bq6ZW5rf.cjs +0 -51
  49. package/lib/node_modules/.pnpm/vitest@4.0.18_@types_node@25.1.0_@vitest_ui@4.0.18_happy-dom@20.0.11_jiti@2.4.2_jsdom@26.1.0__pd2l5poczrcnqygjcqiguyknnm/node_modules/vitest/dist/chunks/date.Bq6ZW5rf.mjs +0 -51
  50. package/lib/node_modules/.pnpm/vitest@4.0.18_@types_node@25.1.0_@vitest_ui@4.0.18_happy-dom@20.0.11_jiti@2.4.2_jsdom@26.1.0__pd2l5poczrcnqygjcqiguyknnm/node_modules/vitest/dist/chunks/utils.DvEY5TfP.cjs +0 -45
  51. package/lib/node_modules/.pnpm/vitest@4.0.18_@types_node@25.1.0_@vitest_ui@4.0.18_happy-dom@20.0.11_jiti@2.4.2_jsdom@26.1.0__pd2l5poczrcnqygjcqiguyknnm/node_modules/vitest/dist/chunks/utils.DvEY5TfP.mjs +0 -45
  52. package/lib/node_modules/.pnpm/vitest@4.0.18_@types_node@25.1.0_@vitest_ui@4.0.18_happy-dom@20.0.11_jiti@2.4.2_jsdom@26.1.0__pd2l5poczrcnqygjcqiguyknnm/node_modules/vitest/dist/chunks/vi.2VT5v0um.cjs +0 -2609
  53. package/lib/node_modules/.pnpm/vitest@4.0.18_@types_node@25.1.0_@vitest_ui@4.0.18_happy-dom@20.0.11_jiti@2.4.2_jsdom@26.1.0__pd2l5poczrcnqygjcqiguyknnm/node_modules/vitest/dist/chunks/vi.2VT5v0um.mjs +0 -2609
@@ -1,13 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const qwik = require("@builder.io/qwik");
4
- const vi_2VT5v0um = require("../node_modules/.pnpm/vitest@4.0.18_@types_node@25.1.0_@vitest_ui@4.0.18_happy-dom@20.0.11_jiti@2.4.2_jsdom@26.1.0__pd2l5poczrcnqygjcqiguyknnm/node_modules/vitest/dist/chunks/vi.2VT5v0um.cjs");
5
- const mockQrl = (_callbackQrl) => {
6
- return qwik.$(vi_2VT5v0um.v.fn());
7
- };
8
- const mock$ = qwik.implicit$FirstArg(mockQrl);
4
+ const vitest = require("vitest");
5
+ function mockQrl(implQrl) {
6
+ const mockFn = vitest.vi.fn(implQrl?.resolved);
7
+ if (implQrl && !mockFn.getMockImplementation()) {
8
+ implQrl.resolve().then((impl) => mockFn.mockImplementation(impl));
9
+ }
10
+ const qrl = qwik.$(mockFn);
11
+ return new Proxy(qrl, {
12
+ get(target, prop, receiver) {
13
+ if (!(prop in target) && prop in mockFn) {
14
+ const value = mockFn[prop];
15
+ return typeof value === "function" ? value.bind(mockFn) : value;
16
+ }
17
+ return Reflect.get(target, prop, receiver);
18
+ },
19
+ has(target, prop) {
20
+ return Reflect.has(target, prop) || Reflect.has(mockFn, prop);
21
+ }
22
+ });
23
+ }
24
+ function mock$(impl) {
25
+ return mockQrl(impl ? qwik.$(impl) : void 0);
26
+ }
9
27
  function clearAllMocks() {
10
- vi_2VT5v0um.v.clearAllMocks();
28
+ vitest.vi.clearAllMocks();
11
29
  }
12
30
  exports.clearAllMocks = clearAllMocks;
13
31
  exports.mock$ = mock$;
@@ -1,9 +1,27 @@
1
- import { implicit$FirstArg, $ } from "@builder.io/qwik";
2
- import { v as vi } from "../node_modules/.pnpm/vitest@4.0.18_@types_node@25.1.0_@vitest_ui@4.0.18_happy-dom@20.0.11_jiti@2.4.2_jsdom@26.1.0__pd2l5poczrcnqygjcqiguyknnm/node_modules/vitest/dist/chunks/vi.2VT5v0um.mjs";
3
- const mockQrl = (_callbackQrl) => {
4
- return $(vi.fn());
5
- };
6
- const mock$ = implicit$FirstArg(mockQrl);
1
+ import { $ } from "@builder.io/qwik";
2
+ import { vi } from "vitest";
3
+ function mockQrl(implQrl) {
4
+ const mockFn = vi.fn(implQrl?.resolved);
5
+ if (implQrl && !mockFn.getMockImplementation()) {
6
+ implQrl.resolve().then((impl) => mockFn.mockImplementation(impl));
7
+ }
8
+ const qrl = $(mockFn);
9
+ return new Proxy(qrl, {
10
+ get(target, prop, receiver) {
11
+ if (!(prop in target) && prop in mockFn) {
12
+ const value = mockFn[prop];
13
+ return typeof value === "function" ? value.bind(mockFn) : value;
14
+ }
15
+ return Reflect.get(target, prop, receiver);
16
+ },
17
+ has(target, prop) {
18
+ return Reflect.has(target, prop) || Reflect.has(mockFn, prop);
19
+ }
20
+ });
21
+ }
22
+ function mock$(impl) {
23
+ return mockQrl(impl ? $(impl) : void 0);
24
+ }
7
25
  function clearAllMocks() {
8
26
  vi.clearAllMocks();
9
27
  }
@@ -1 +1,2 @@
1
- export * from "./lib/qwik-mock";
1
+ export { clearAllMocks, mock$, mockQrl } from "./lib/qwik-mock";
2
+ export type { QrlMock } from "./lib/qwik-mock";
@@ -1,35 +1,37 @@
1
1
  import { type QRL } from "@builder.io/qwik";
2
2
  import { type Mock } from "vitest";
3
+ /**
4
+ * A mock that can be passed as a component callback prop (`onClick$`, `onChange$`, etc.)
5
+ * and asserted on directly with `expect()`.
6
+ */
7
+ export type QrlMock<T extends (...args: any[]) => any = (...args: any[]) => any> = QRL<T> & Mock<T>;
8
+ /** @internal Called by the Qwik optimizer — use {@link mock$} instead. */
9
+ export declare function mockQrl<T extends (...args: any[]) => any = (...args: any[]) => any>(implQrl?: QRL<T>): QrlMock<T>;
3
10
  /**
4
11
  * @experimental
5
12
  *
6
- * Create a QRL mock that can be used in tests to verify interactions.
13
+ * Create a mock for a component callback prop (`onClick$`, `onChange$`, etc.).
14
+ *
15
+ * Pass it to a component like any other `$` prop, then assert on it directly —
16
+ * no need to resolve.
7
17
  *
8
- * As Qwik is an async framework, you need to `resolve()` the mock before making your verifications.
9
- * And remember to clear the mocks before each test to start with a clean slate!
18
+ * @param impl - Optional implementation function for the mock.
10
19
  *
11
20
  * @example
12
21
  * ```tsx
13
- * describe('<MyButton />', () => {
14
- * beforeEach(() => {
15
- * clearAllMocks();
16
- * });
22
+ * const onClickMock = mock$();
23
+ * await render(<MyButton onClick$={onClickMock} />);
17
24
  *
18
- * it('should call onClick$', async () => {
19
- * const onClickMock = mock$();
20
- * await render(<MyButton onClick$={onClickMock} />);
25
+ * await userEvent.click(screen.getByRole('button'));
21
26
  *
22
- * await userEvent.click(screen.getByRole('button'));
23
- *
24
- * await waitFor(() => expect(onClickMock.resolve()).resolves.toHaveBeenCalled());
25
- * });
26
- * });
27
+ * await waitFor(() => expect(onClickMock).toHaveBeenCalled());
27
28
  * ```
28
29
  */
29
- export declare const mockQrl: (_callbackQrl: QRL<(...args: any[]) => any>) => QRL<Mock>;
30
- export declare const mock$: (qrl: (...args: any[]) => any) => QRL<Mock>;
30
+ export declare function mock$<T extends (...args: any[]) => any = (...args: any[]) => any>(impl?: T): QrlMock<T>;
31
31
  /**
32
- * Will call `.mockClear()` on all spies. This will clear mock history, but not reset its implementation to the
33
- * default one.
32
+ * Clear mock history on all mocks created with {@link mock$}.
33
+ * Does not reset their implementation.
34
+ *
35
+ * Typically called in `beforeEach` to start each test with a clean slate.
34
36
  */
35
37
  export declare function clearAllMocks(): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noma.to/qwik-mock",
3
- "version": "1.0.2",
3
+ "version": "1.1.1",
4
4
  "description": "Small utility to mock Qwik QRLs",
5
5
  "repository": "https://github.com/ianlet/qwik-testing-library",
6
6
  "homepage": "https://github.com/ianlet/qwik-testing-library",
@@ -34,19 +34,20 @@
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/eslint": "8.56.10",
37
- "@types/node": "25.1.0",
38
- "@typescript-eslint/eslint-plugin": "8.54.0",
39
- "@typescript-eslint/parser": "8.54.0",
37
+ "@types/node": "25.3.3",
38
+ "@typescript-eslint/eslint-plugin": "8.56.1",
39
+ "@typescript-eslint/parser": "8.56.1",
40
40
  "eslint": "8.57.1",
41
41
  "eslint-plugin-qwik": "1.19.0",
42
42
  "prettier": "3.8.1",
43
43
  "typescript": "5.9.3",
44
44
  "undici": "*",
45
45
  "vite": "7.3.1",
46
- "vite-tsconfig-paths": "^6.0.5",
46
+ "vite-tsconfig-paths": "^6.1.1",
47
47
  "vitest": "^4.0.18"
48
48
  },
49
49
  "peerDependencies": {
50
- "@builder.io/qwik": ">= 1.12.0 < 2"
50
+ "@builder.io/qwik": ">= 1.12.0 < 2",
51
+ "vitest": ">= 3.0.0"
51
52
  }
52
53
  }
@@ -1,83 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- var comma = ",".charCodeAt(0);
4
- var semicolon = ";".charCodeAt(0);
5
- var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
6
- var intToChar = new Uint8Array(64);
7
- var charToInt = new Uint8Array(128);
8
- for (let i = 0; i < chars.length; i++) {
9
- const c = chars.charCodeAt(i);
10
- intToChar[i] = c;
11
- charToInt[c] = i;
12
- }
13
- function encodeInteger(builder, num, relative) {
14
- let delta = num - relative;
15
- delta = delta < 0 ? -delta << 1 | 1 : delta << 1;
16
- do {
17
- let clamped = delta & 31;
18
- delta >>>= 5;
19
- if (delta > 0) clamped |= 32;
20
- builder.write(intToChar[clamped]);
21
- } while (delta > 0);
22
- return num;
23
- }
24
- var bufLength = 1024 * 16;
25
- var td = typeof TextDecoder !== "undefined" ? /* @__PURE__ */ new TextDecoder() : typeof Buffer !== "undefined" ? {
26
- decode(buf) {
27
- const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
28
- return out.toString();
29
- }
30
- } : {
31
- decode(buf) {
32
- let out = "";
33
- for (let i = 0; i < buf.length; i++) {
34
- out += String.fromCharCode(buf[i]);
35
- }
36
- return out;
37
- }
38
- };
39
- var StringWriter = class {
40
- constructor() {
41
- this.pos = 0;
42
- this.out = "";
43
- this.buffer = new Uint8Array(bufLength);
44
- }
45
- write(v) {
46
- const { buffer } = this;
47
- buffer[this.pos++] = v;
48
- if (this.pos === bufLength) {
49
- this.out += td.decode(buffer);
50
- this.pos = 0;
51
- }
52
- }
53
- flush() {
54
- const { buffer, out, pos } = this;
55
- return pos > 0 ? out + td.decode(buffer.subarray(0, pos)) : out;
56
- }
57
- };
58
- function encode(decoded) {
59
- const writer = new StringWriter();
60
- let sourcesIndex = 0;
61
- let sourceLine = 0;
62
- let sourceColumn = 0;
63
- let namesIndex = 0;
64
- for (let i = 0; i < decoded.length; i++) {
65
- const line = decoded[i];
66
- if (i > 0) writer.write(semicolon);
67
- if (line.length === 0) continue;
68
- let genColumn = 0;
69
- for (let j = 0; j < line.length; j++) {
70
- const segment = line[j];
71
- if (j > 0) writer.write(comma);
72
- genColumn = encodeInteger(writer, segment[0], genColumn);
73
- if (segment.length === 1) continue;
74
- sourcesIndex = encodeInteger(writer, segment[1], sourcesIndex);
75
- sourceLine = encodeInteger(writer, segment[2], sourceLine);
76
- sourceColumn = encodeInteger(writer, segment[3], sourceColumn);
77
- if (segment.length === 4) continue;
78
- namesIndex = encodeInteger(writer, segment[4], namesIndex);
79
- }
80
- }
81
- return writer.flush();
82
- }
83
- exports.encode = encode;
@@ -1,83 +0,0 @@
1
- var comma = ",".charCodeAt(0);
2
- var semicolon = ";".charCodeAt(0);
3
- var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
4
- var intToChar = new Uint8Array(64);
5
- var charToInt = new Uint8Array(128);
6
- for (let i = 0; i < chars.length; i++) {
7
- const c = chars.charCodeAt(i);
8
- intToChar[i] = c;
9
- charToInt[c] = i;
10
- }
11
- function encodeInteger(builder, num, relative) {
12
- let delta = num - relative;
13
- delta = delta < 0 ? -delta << 1 | 1 : delta << 1;
14
- do {
15
- let clamped = delta & 31;
16
- delta >>>= 5;
17
- if (delta > 0) clamped |= 32;
18
- builder.write(intToChar[clamped]);
19
- } while (delta > 0);
20
- return num;
21
- }
22
- var bufLength = 1024 * 16;
23
- var td = typeof TextDecoder !== "undefined" ? /* @__PURE__ */ new TextDecoder() : typeof Buffer !== "undefined" ? {
24
- decode(buf) {
25
- const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
26
- return out.toString();
27
- }
28
- } : {
29
- decode(buf) {
30
- let out = "";
31
- for (let i = 0; i < buf.length; i++) {
32
- out += String.fromCharCode(buf[i]);
33
- }
34
- return out;
35
- }
36
- };
37
- var StringWriter = class {
38
- constructor() {
39
- this.pos = 0;
40
- this.out = "";
41
- this.buffer = new Uint8Array(bufLength);
42
- }
43
- write(v) {
44
- const { buffer } = this;
45
- buffer[this.pos++] = v;
46
- if (this.pos === bufLength) {
47
- this.out += td.decode(buffer);
48
- this.pos = 0;
49
- }
50
- }
51
- flush() {
52
- const { buffer, out, pos } = this;
53
- return pos > 0 ? out + td.decode(buffer.subarray(0, pos)) : out;
54
- }
55
- };
56
- function encode(decoded) {
57
- const writer = new StringWriter();
58
- let sourcesIndex = 0;
59
- let sourceLine = 0;
60
- let sourceColumn = 0;
61
- let namesIndex = 0;
62
- for (let i = 0; i < decoded.length; i++) {
63
- const line = decoded[i];
64
- if (i > 0) writer.write(semicolon);
65
- if (line.length === 0) continue;
66
- let genColumn = 0;
67
- for (let j = 0; j < line.length; j++) {
68
- const segment = line[j];
69
- if (j > 0) writer.write(comma);
70
- genColumn = encodeInteger(writer, segment[0], genColumn);
71
- if (segment.length === 1) continue;
72
- sourcesIndex = encodeInteger(writer, segment[1], sourcesIndex);
73
- sourceLine = encodeInteger(writer, segment[2], sourceLine);
74
- sourceColumn = encodeInteger(writer, segment[3], sourceColumn);
75
- if (segment.length === 4) continue;
76
- namesIndex = encodeInteger(writer, segment[4], namesIndex);
77
- }
78
- }
79
- return writer.flush();
80
- }
81
- export {
82
- encode
83
- };