@noma.to/qwik-testing-library 1.0.3 → 1.0.4

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 (2) hide show
  1. package/README.md +59 -7
  2. package/package.json +8 -8
package/README.md CHANGED
@@ -37,7 +37,7 @@ src="https://raw.githubusercontent.com/ianlet/qwik-testing-library/main/high-vol
37
37
 
38
38
  [qtl-docs-repo]: https://github.com/ianlet/qwik-testing-library/blob/main/README.md
39
39
 
40
- [build-badge]: https://img.shields.io/github/actions/workflow/status/ianlet/qwik-testing-library/release.yml?style=flat-square
40
+ [build-badge]: https://img.shields.io/github/actions/workflow/status/ianlet/qwik-testing-library/ci.yml?style=flat-square
41
41
 
42
42
  [build]: https://github.com/ianlet/qwik-testing-library/actions
43
43
 
@@ -91,12 +91,13 @@ src="https://raw.githubusercontent.com/ianlet/qwik-testing-library/main/high-vol
91
91
  - [Installation](#installation)
92
92
  - [Setup](#setup)
93
93
  - [Examples](#examples)
94
- - [Qwikstart](#qwikstart)
94
+ - [Qwikstart](#qwikstart)
95
+ - [Qwik City - `server$` calls](#qwik-city---server-calls)
95
96
  - [Gotchas](#gotchas)
96
97
  - [Issues](#issues)
97
- - [🐛 Bugs](#-bugs)
98
- - [💡 Feature Requests](#-feature-requests)
99
- - [❓ Questions](#-questions)
98
+ - [🐛 Bugs](#-bugs)
99
+ - [💡 Feature Requests](#-feature-requests)
100
+ - [❓ Questions](#-questions)
100
101
  - [Contributors](#contributors)
101
102
  - [Acknowledgements](#acknowledgements)
102
103
 
@@ -131,7 +132,7 @@ npm install --save-dev @noma.to/qwik-testing-library
131
132
 
132
133
  This library supports `qwik` versions `1.7.2` and above.
133
134
 
134
- You may also be interested in installing `@testing-library/jest-dom` so you can
135
+ You may also be interested in installing `@testing-library/jest-dom` and `@testing-library/user-event` so you can
135
136
  use [the custom jest matchers][jest-dom] and [the user event library][user-event] to test interactions with the DOM.
136
137
 
137
138
  ```shell
@@ -294,12 +295,63 @@ describe("<Counter />", () => {
294
295
  await userEvent.click(incrementBtn);
295
296
  await userEvent.click(incrementBtn);
296
297
 
297
- // assert that the counter is now 1
298
+ // assert that the counter is now 2
298
299
  await waitFor(() => expect(screen.getByText(/count:2/)).toBeInTheDocument());
299
300
  });
300
301
  })
301
302
  ```
302
303
 
304
+ ### Qwik City - `server$` calls
305
+
306
+ If one of your Qwik components uses `server$` calls, your tests might fail with a rather cryptic message (e.g. `QWIK
307
+ ERROR __vite_ssr_import_0__.myServerFunctionQrl is not a function` or
308
+ `QWIK ERROR Failed to parse URL from ?qfunc=DNpotUma33o`).
309
+
310
+ We're happy to discuss it on [Discord][discord], but we consider this failure to be a good thing:
311
+ your components should be tested in isolation, so you will be forced to mock your server functions.
312
+
313
+ Here is an example of how to test a component that uses `server$` calls:
314
+
315
+ ```ts
316
+ // ~/server/blog-posts.ts
317
+
318
+ import {server$} from "@builder.io/qwik-city";
319
+ import {BlogPost} from "~/lib/blog-post";
320
+
321
+ export const getLatestPosts$ = server$(function (): Promise<BlogPost> {
322
+ // get the latest posts
323
+ return Promise.resolve([]);
324
+ });
325
+ ```
326
+
327
+ ```tsx
328
+ // ~/components/latest-post-list.spec.tsx
329
+
330
+ import {render, screen, waitFor} from "@noma.to/qwik-testing-library";
331
+ import {LatestPostList} from "./latest-post-list";
332
+
333
+ vi.mock('~/server/blog-posts', () => ({
334
+ // the mocked function should end with `Qrl` instead of `$`
335
+ getLatestPostsQrl: () => {
336
+ return Promise.resolve([{id: 'post-1', title: 'Post 1'}, {id: 'post-2', title: 'Post 2'}]);
337
+ },
338
+ }));
339
+
340
+ describe('<LatestPostList />', () => {
341
+ it('should render the latest posts', async () => {
342
+ await render(<LatestPostList/>);
343
+
344
+ await waitFor(() => expect(screen.queryAllByRole('listitem')).toHaveLength(2));
345
+ });
346
+ });
347
+ ```
348
+
349
+ Notice how the mocked function is ending with `Qrl` instead of `$`, despite being named as `getLatestPosts$`.
350
+ This is caused by the Qwik optimizer renaming it to `Qrl`.
351
+ So, we need to mock the `Qrl` function instead of the original `$` one.
352
+
353
+ If your `server$` function doesn't end with `$`, the Qwik optimizer might not rename it to `Qrl`.
354
+
303
355
  ## Gotchas
304
356
 
305
357
  * Watch mode (at least in Webstorm) doesn't seem to work well: components are not being updated with your latest changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noma.to/qwik-testing-library",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
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",
@@ -37,15 +37,15 @@
37
37
  "@builder.io/qwik": "1.9.0",
38
38
  "@testing-library/dom": "^10.4.0",
39
39
  "@types/eslint": "8.56.10",
40
- "@types/node": "20.14.11",
41
- "@typescript-eslint/eslint-plugin": "7.16.1",
42
- "@typescript-eslint/parser": "7.16.1",
43
- "eslint": "8.57.0",
40
+ "@types/node": "22.7.4",
41
+ "@typescript-eslint/eslint-plugin": "8.7.0",
42
+ "@typescript-eslint/parser": "8.7.0",
43
+ "eslint": "8.57.1",
44
44
  "eslint-plugin-qwik": "1.9.0",
45
45
  "prettier": "3.3.3",
46
- "typescript": "5.4.5",
46
+ "typescript": "5.6.2",
47
47
  "undici": "*",
48
- "vite": "5.3.5",
49
- "vite-tsconfig-paths": "^4.2.1"
48
+ "vite": "5.4.8",
49
+ "vite-tsconfig-paths": "^5.0.1"
50
50
  }
51
51
  }