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

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 (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +388 -0
  3. package/package.json +4 -1
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Ian Letourneau <letourneau.ian@gmail.com> (https://github.com/ianlet)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,388 @@
1
+ <div align="center">
2
+ <h1>Qwik Testing Library</h1>
3
+
4
+ <img
5
+ height="80"
6
+ width="80"
7
+ alt="qwik-testing-library logo depicts a high voltage emoji"
8
+ src="https://raw.githubusercontent.com/ianlet/qwik-testing-library/main/high-voltage.png"
9
+ />
10
+
11
+ <p>Simple and complete Qwik testing utilities that encourage good testing practices.</p>
12
+
13
+ [**Read The Docs**][qtl-docs] | [Edit the docs][qtl-docs-repo]
14
+
15
+ <!-- prettier-ignore-start -->
16
+ [![Build Status][build-badge]][build]
17
+ [![version][version-badge]][package]
18
+ [![downloads][downloads-badge]][downloads]
19
+ [![MIT License][license-badge]][license]
20
+
21
+ <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
22
+ [![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors-)
23
+ <!-- ALL-CONTRIBUTORS-BADGE:END -->
24
+ [![PRs Welcome][prs-badge]][prs]
25
+ [![Code of Conduct][coc-badge]][coc]
26
+ [![Discord][discord-badge]][discord]
27
+
28
+ [![Watch on GitHub][github-watch-badge]][github-watch]
29
+ [![Star on GitHub][github-star-badge]][github-star]
30
+ [![Tweet][twitter-badge]][twitter]
31
+ <!-- prettier-ignore-end -->
32
+ </div>
33
+
34
+ <hr />
35
+
36
+ [qtl-docs]: #installation
37
+
38
+ [qtl-docs-repo]: https://github.com/ianlet/qwik-testing-library/blob/main/README.md
39
+
40
+ [build-badge]: https://img.shields.io/github/actions/workflow/status/ianlet/qwik-testing-library/release.yml?style=flat-square
41
+
42
+ [build]: https://github.com/ianlet/qwik-testing-library/actions
43
+
44
+ [coverage-badge]: https://img.shields.io/codecov/c/github/ianlet/qwik-testing-library.svg?style=flat-square
45
+
46
+ [coverage]: https://codecov.io/github/ianlet/qwik-testing-library
47
+
48
+ [version-badge]: https://img.shields.io/npm/v/@noma.to/qwik-testing-library.svg?style=flat-square
49
+
50
+ [package]: https://www.npmjs.com/package/@noma.to/qwik-testing-library
51
+
52
+ [downloads-badge]: https://img.shields.io/npm/dm/@noma.to/qwik-testing-library.svg?style=flat-square
53
+
54
+ [downloads]: http://www.npmtrends.com/@noma.to/qwik-testing-library
55
+
56
+ [license-badge]: https://img.shields.io/github/license/ianlet/qwik-testing-library?color=b&style=flat-square
57
+
58
+ [license]: https://github.com/ianlet/qwik-testing-library/blob/main/LICENSE
59
+
60
+ [prs-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square
61
+
62
+ [prs]: http://makeapullrequest.com
63
+
64
+ [coc-badge]: https://img.shields.io/badge/code%20of-conduct-ff69b4.svg?style=flat-square
65
+
66
+ [coc]: https://github.com/ianlet/qwik-testing-library/blob/main/CODE_OF_CONDUCT.md
67
+
68
+ [discord-badge]: https://img.shields.io/discord/723559267868737556.svg?color=7389D8&labelColor=6A7EC2&logo=discord&logoColor=ffffff&style=flat-square
69
+
70
+ [discord]: https://qwik.dev/chat
71
+
72
+ [github-watch-badge]: https://img.shields.io/github/watchers/ianlet/qwik-testing-library.svg?style=social
73
+
74
+ [github-watch]: https://github.com/ianlet/qwik-testing-library/watchers
75
+
76
+ [github-star-badge]: https://img.shields.io/github/stars/ianlet/qwik-testing-library.svg?style=social
77
+
78
+ [github-star]: https://github.com/ianlet/qwik-testing-library/stargazers
79
+
80
+ [twitter]: https://twitter.com/intent/tweet?text=Check%20out%20qwik-testing-library%20by%20%40noma_hq%20https%3A%2F%2Fgithub.com%2Fianlet%2Fqwik-testing-library%20%F0%9F%91%8D
81
+
82
+ [twitter-badge]: https://img.shields.io/twitter/url/https/github.com/ianlet/qwik-testing-library.svg?style=social
83
+
84
+ ## Table of Contents
85
+
86
+ <!-- START doctoc generated TOC please keep comment here to allow auto update -->
87
+ <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
88
+
89
+ - [The Problem](#the-problem)
90
+ - [This Solution](#this-solution)
91
+ - [Installation](#installation)
92
+ - [Setup](#setup)
93
+ - [Examples](#examples)
94
+ - [Qwikstart](#qwikstart)
95
+ - [Gotchas](#gotchas)
96
+ - [Issues](#issues)
97
+ - [🐛 Bugs](#-bugs)
98
+ - [💡 Feature Requests](#-feature-requests)
99
+ - [❓ Questions](#-questions)
100
+ - [Contributors](#contributors)
101
+ - [Acknowledgements](#acknowledgements)
102
+
103
+ <!-- END doctoc generated TOC please keep comment here to allow auto update -->
104
+
105
+ ## The Problem
106
+
107
+ You want to write maintainable tests for your [Qwik][qwik] components.
108
+
109
+ [qwik]: https://qwik.dev/
110
+
111
+ ## This Solution
112
+
113
+ `@noma.to/qwik-testing-library` is a lightweight library for testing Qwik
114
+ components. It provides functions on top of `qwik` and
115
+ `@testing-library/dom` so you can mount Qwik components and query their
116
+ rendered output in the DOM. Its primary guiding principle is:
117
+
118
+ > [The more your tests resemble the way your software is used, the more
119
+ > confidence they can give you.][guiding-principle]
120
+
121
+ [guiding-principle]: https://twitter.com/kentcdodds/status/977018512689455106
122
+
123
+ ## Installation
124
+
125
+ This module is distributed via [npm][npm] which is bundled with [node][node] and
126
+ should be installed as one of your project's `devDependencies`:
127
+
128
+ ```shell
129
+ npm install --save-dev @noma.to/qwik-testing-library
130
+ ```
131
+
132
+ This library supports `qwik` versions `1.7.2` and above.
133
+
134
+ You may also be interested in installing `@testing-library/jest-dom` so you can
135
+ use [the custom jest matchers][jest-dom] and [the user event library][user-event] to test interactions with the DOM.
136
+
137
+ ```shell
138
+ npm install --save-dev @testing-library/jest-dom @testing-library/user-event
139
+ ```
140
+
141
+ Finally, we need a DOM environment to run the tests in.
142
+ This library was tested (for now) only with `jsdom` so we recommend using it:
143
+
144
+ ```shell
145
+ npm install --save-dev jsdom
146
+ ```
147
+
148
+ [npm]: https://www.npmjs.com/
149
+
150
+ [node]: https://nodejs.org
151
+
152
+ [jest-dom]: https://github.com/testing-library/jest-dom
153
+
154
+ [user-event]: https://github.com/testing-library/user-event
155
+
156
+ ## Setup
157
+
158
+ We recommend using `@noma.to/qwik-testing-library` with [Vitest][] as your test
159
+ runner.
160
+
161
+ If you haven't done so already, add vitest to your project using Qwik CLI:
162
+
163
+ ```shell
164
+ npm qwik add vitest
165
+ ```
166
+
167
+ After that, we need to configure Vitest so it can run your tests.
168
+ For this, create a _separate_ `vitest.config.ts` so you don't have to modify your project's `vite.config.ts`:
169
+
170
+ ```ts
171
+ // vitest.config.ts
172
+
173
+ import {defineConfig, mergeConfig} from "vitest/config";
174
+ import viteConfig from "./vite.config";
175
+
176
+ export default defineConfig((configEnv) =>
177
+ mergeConfig(
178
+ viteConfig(configEnv),
179
+ defineConfig({
180
+ // qwik-testing-library needs to consider your project as a Qwik lib
181
+ // if it's already a Qwik lib, you can remove this section
182
+ build: {
183
+ target: "es2020",
184
+ lib: {
185
+ entry: "./src/index.ts",
186
+ formats: ["es", "cjs"],
187
+ fileName: (format, entryName) =>
188
+ `${entryName}.qwik.${format === "es" ? "mjs" : "cjs"}`,
189
+ },
190
+ },
191
+ // configure your test environment
192
+ test: {
193
+ environment: "jsdom",
194
+ setupFiles: ["./vitest.setup.ts"],
195
+ globals: true,
196
+ },
197
+ }),
198
+ ),
199
+ );
200
+ ```
201
+
202
+ For now, `qwik-testing-library` needs to consider your project as a lib ([PR welcomed][prs] to simplify this).
203
+ Hence, the `build.lib` section in the config above.
204
+
205
+ As the build will try to use `./src/index.ts` as the entry point, we need to create it:
206
+
207
+ ```ts
208
+ // ./src/index.ts
209
+
210
+ /**
211
+ * DO NOT DELETE THIS FILE
212
+ *
213
+ * This entrypoint is needed by @noma.to/qwik-testing-library to run your tests
214
+ */
215
+ ```
216
+
217
+ Then, create the `vitest.setup.ts` file:
218
+
219
+ ```ts
220
+ // vitest.setup.ts
221
+
222
+ import {afterEach} from "vitest";
223
+ import "@testing-library/jest-dom/vitest";
224
+
225
+ // This has to run before qdev.ts loads. `beforeAll` is too late
226
+ globalThis.qTest = false; // Forces Qwik to run as if it was in a Browser
227
+ globalThis.qRuntimeQrl = true;
228
+ globalThis.qDev = true;
229
+ globalThis.qInspector = false;
230
+
231
+ afterEach(async () => {
232
+ const {cleanup} = await import("@noma.to/qwik-testing-library");
233
+ cleanup();
234
+ });
235
+ ```
236
+
237
+ This setup will make sure that Qwik is properly configured and that everything gets cleaned after each test.
238
+
239
+ Additionally, it loads `@testing-library/jest-dom/vitest` in your test runner so you can use matchers like
240
+ `expect(...).toBeInTheDocument()`.
241
+
242
+ Finally, edit your `tsconfig.json` to declare the following global types:
243
+
244
+ ```diff
245
+ // tsconfig.json
246
+
247
+ {
248
+ "compilerOptions": {
249
+ "types": [
250
+ + "vite/client",
251
+ + "vitest/globals",
252
+ + "@testing-library/jest-dom/vitest"
253
+ ]
254
+ },
255
+ "include": ["src"]
256
+ }
257
+ ```
258
+
259
+ [vitest]: https://vitest.dev/
260
+
261
+ ## Examples
262
+
263
+ Below are some examples of how to use `@noma.to/qwik-testing-library` to tests your Qwik components.
264
+
265
+ You can also learn more about the [**queries**][tl-queries-docs] and [**user events**][tl-user-events-docs] over at the
266
+ Testing Library website.
267
+
268
+ [tl-queries-docs]: https://testing-library.com/docs/queries/about
269
+
270
+ [tl-user-events-docs]: https://testing-library.com/docs/user-event/intro
271
+
272
+ ### Qwikstart
273
+
274
+ This is a minimal setup to get you started, with line-by-line explanations.
275
+
276
+ ```tsx
277
+ // counter.spec.tsx
278
+
279
+ // import qwik-testing methods
280
+ import {screen, render, waitFor} from "@noma.to/qwik-testing-library";
281
+ // import the component to be tested
282
+ import {Counter} from "./counter";
283
+
284
+ // describe the test suite
285
+ describe("<Counter />", () => {
286
+ // describe the test case
287
+ it("should increment the counter", async () => {
288
+ // render the component into the DOM
289
+ await render(<Counter/>);
290
+
291
+ // retrieve the 'increment count' button
292
+ const incrementBtn = screen.getByRole("button", {name: /increment count/});
293
+ // click the button twice
294
+ await userEvent.click(incrementBtn);
295
+ await userEvent.click(incrementBtn);
296
+
297
+ // assert that the counter is now 1
298
+ await waitFor(() => expect(screen.getByText(/count:2/)).toBeInTheDocument());
299
+ });
300
+ })
301
+ ```
302
+
303
+ ## Gotchas
304
+
305
+ * Watch mode (at least in Webstorm) doesn't seem to work well: components are not being updated with your latest changes
306
+
307
+ ## Issues
308
+
309
+ _Looking to contribute? Look for the [Good First Issue][good-first-issue]
310
+ label._
311
+
312
+ [good-first-issue]: https://github.com/ianlet/qwik-testing-library/issues?utf8=✓&q=is%3Aissue+is%3Aopen+sort%3Areactions-%2B1-desc+label%3A"good+first+issue"+
313
+
314
+ ### 🐛 Bugs
315
+
316
+ Please file an issue for bugs, missing documentation, or unexpected behavior.
317
+
318
+ [**See Bugs**][bugs]
319
+
320
+ [bugs]: https://github.com/ianlet/qwik-testing-library/issues?q=is%3Aissue+is%3Aopen+label%3Abug+sort%3Acreated-desc
321
+
322
+ ### 💡 Feature Requests
323
+
324
+ Please file an issue to suggest new features. Vote on feature requests by adding
325
+ a 👍. This helps maintainers prioritize what to work on.
326
+
327
+ [**See Feature Requests**][requests]
328
+
329
+ [requests]: https://github.com/ianlet/qwik-testing-library/issues?q=is%3Aissue+sort%3Areactions-%2B1-desc+label%3Aenhancement+is%3Aopen
330
+
331
+ ### ❓ Questions
332
+
333
+ For questions related to using the library, please visit a support community
334
+ instead of filing an issue on GitHub.
335
+
336
+ - [Discord][discord]
337
+ - [Stack Overflow][stackoverflow]
338
+
339
+ [stackoverflow]: https://stackoverflow.com/questions/tagged/qwik-testing-library
340
+
341
+ ## Contributors
342
+
343
+ Thanks goes to these people ([emoji key][emojis]):
344
+ <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
345
+ <!-- prettier-ignore-start -->
346
+ <!-- markdownlint-disable -->
347
+ <table>
348
+ <tbody>
349
+ <tr>
350
+ <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>
351
+ </tr>
352
+ </tbody>
353
+ <tfoot>
354
+ <tr>
355
+ <td align="center" size="13px" colspan="7">
356
+ <img src="https://raw.githubusercontent.com/all-contributors/all-contributors-cli/1b8533af435da9854653492b1327a23a4dbd0a10/assets/logo-small.svg">
357
+ <a href="https://all-contributors.js.org/docs/en/bot/usage">Add your contributions</a>
358
+ </img>
359
+ </td>
360
+ </tr>
361
+ </tfoot>
362
+ </table>
363
+
364
+ <!-- markdownlint-restore -->
365
+ <!-- prettier-ignore-end -->
366
+
367
+ <!-- ALL-CONTRIBUTORS-LIST:END -->
368
+
369
+ This project follows the [all-contributors][all-contributors] specification.
370
+ Contributions of any kind welcome!
371
+
372
+ [emojis]: https://github.com/all-contributors/all-contributors#emoji-key
373
+
374
+ [all-contributors]: https://github.com/all-contributors/all-contributors
375
+
376
+ ## Acknowledgements
377
+
378
+ Massive thanks to the [Qwik Team][qwik-team] and the whole community for their efforts to build Qwik and for
379
+ the [inspiration][qwik-baseline] on how to create a testing library for Qwik.
380
+
381
+ Thanks to the [Testing Library Team][tl-team] for a great set of tools to build better products, confidently, and
382
+ qwikly.
383
+
384
+ [qwik-team]: https://github.com/QwikDev/qwik/
385
+
386
+ [qwik-baseline]: https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/testing
387
+
388
+ [tl-team]: https://testing-library.com
package/package.json CHANGED
@@ -1,7 +1,10 @@
1
1
  {
2
2
  "name": "@noma.to/qwik-testing-library",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Simple and complete Qwik testing utilities that encourage good testing practices.",
5
+ "repository": "https://github.com/ianlet/qwik-testing-library",
6
+ "homepage": "https://github.com/ianlet/qwik-testing-library",
7
+ "license": "MIT",
5
8
  "main": "./lib/index.qwik.mjs",
6
9
  "qwik": "./lib/index.qwik.mjs",
7
10
  "types": "./lib-types/index.d.ts",