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

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 +332 -0
  3. package/package.json +3 -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,332 @@
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].
136
+
137
+ [npm]: https://www.npmjs.com/
138
+
139
+ [node]: https://nodejs.org
140
+
141
+ [jest-dom]: https://github.com/testing-library/jest-dom
142
+
143
+ ## Setup
144
+
145
+ We recommend using `@noma.to/qwik-testing-library` with [Vitest][] as your test
146
+ runner. To get started, configure how Vite will run your tests.
147
+
148
+ ```diff
149
+ // vite.config.js
150
+
151
+ export default defineConfig({
152
+ plugins: [qwikVite(), tsconfigPaths()],
153
+ + test: {
154
+ + environment: "jsdom",
155
+ + setupFiles: ["./vitest.setup.ts"],
156
+ + globals: true,
157
+ + },
158
+ });
159
+ ```
160
+
161
+ Then, create the `vitest.setup.ts` file:
162
+
163
+ ```ts
164
+ // vitest.setup.ts
165
+
166
+ import {afterEach} from "vitest";
167
+ import "@testing-library/jest-dom/vitest";
168
+
169
+ // This has to run before qdev.ts loads. `beforeAll` is too late
170
+ globalThis.qTest = false; // Forces Qwik to run as if it was in a Browser
171
+ globalThis.qRuntimeQrl = true;
172
+ globalThis.qDev = true;
173
+ globalThis.qInspector = false;
174
+
175
+ afterEach(async () => {
176
+ const {cleanup} = await import("@noma.to/qwik-testing-library");
177
+ cleanup();
178
+ });
179
+ ```
180
+
181
+ This setup will make sure that Qwik is properly configured and that everything gets cleaned after each test.
182
+
183
+ Additionally, it loads `@testing-library/jest-dom/vitest` in your test runner so you can use matchers like
184
+ `expect(...).toBeInTheDocument()`.
185
+
186
+ Finally, edit your `tsconfig.json` to declare the following global types:
187
+
188
+ ```diff
189
+ // tsconfig.json
190
+
191
+ {
192
+ "compilerOptions": {
193
+ "types": [
194
+ + "vite/client",
195
+ + "vitest/globals",
196
+ + "@testing-library/jest-dom/vitest"
197
+ ]
198
+ },
199
+ "include": ["src"]
200
+ }
201
+ ```
202
+
203
+ [vitest]: https://vitest.dev/
204
+
205
+ ## Examples
206
+
207
+ Below are some examples of how to use `@noma.to/qwik-testing-library` to tests your Qwik components.
208
+
209
+ You can also learn more about the [**queries**][tl-queries-docs] and [**user events**][tl-user-events-docs] over at the
210
+ Testing Library website.
211
+
212
+ [tl-queries-docs]: https://testing-library.com/docs/queries/about
213
+
214
+ [tl-user-events-docs]: https://testing-library.com/docs/user-event/intro
215
+
216
+ ### Qwikstart
217
+
218
+ This is a minimal setup to get you started, with line-by-line explanations.
219
+
220
+ ```tsx
221
+ // counter.spec.tsx
222
+
223
+ // import qwik-testing methods
224
+ import {screen, render, waitFor} from "@noma.to/qwik-testing-library";
225
+ // import the component to be tested
226
+ import {Counter} from "./counter";
227
+
228
+ // describe the test suite
229
+ describe("<Counter />", () => {
230
+ // describe the test case
231
+ it("should increment the counter", async () => {
232
+ // render the component into the DOM
233
+ await render(<Counter/>);
234
+
235
+ // retrieve the 'increment count' button
236
+ const incrementBtn = screen.getByRole("button", {name: /increment count/});
237
+ // click the button twice
238
+ await userEvent.click(incrementBtn);
239
+ await userEvent.click(incrementBtn);
240
+
241
+ // assert that the counter is now 1
242
+ await waitFor(() => expect(screen.getByText(/count:2/)).toBeInTheDocument());
243
+ });
244
+ })
245
+ ```
246
+
247
+ ## Gotchas
248
+
249
+ * Watch mode (at least in Webstorm) doesn't seem to work well: components are not being updated with your latest changes
250
+
251
+ ## Issues
252
+
253
+ _Looking to contribute? Look for the [Good First Issue][good-first-issue]
254
+ label._
255
+
256
+ [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"+
257
+
258
+ ### 🐛 Bugs
259
+
260
+ Please file an issue for bugs, missing documentation, or unexpected behavior.
261
+
262
+ [**See Bugs**][bugs]
263
+
264
+ [bugs]: https://github.com/ianlet/qwik-testing-library/issues?q=is%3Aissue+is%3Aopen+label%3Abug+sort%3Acreated-desc
265
+
266
+ ### 💡 Feature Requests
267
+
268
+ Please file an issue to suggest new features. Vote on feature requests by adding
269
+ a 👍. This helps maintainers prioritize what to work on.
270
+
271
+ [**See Feature Requests**][requests]
272
+
273
+ [requests]: https://github.com/ianlet/qwik-testing-library/issues?q=is%3Aissue+sort%3Areactions-%2B1-desc+label%3Aenhancement+is%3Aopen
274
+
275
+ ### ❓ Questions
276
+
277
+ For questions related to using the library, please visit a support community
278
+ instead of filing an issue on GitHub.
279
+
280
+ - [Discord][discord]
281
+ - [Stack Overflow][stackoverflow]
282
+
283
+ [stackoverflow]: https://stackoverflow.com/questions/tagged/qwik-testing-library
284
+
285
+ ## Contributors
286
+
287
+ Thanks goes to these people ([emoji key][emojis]):
288
+ <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
289
+ <!-- prettier-ignore-start -->
290
+ <!-- markdownlint-disable -->
291
+ <table>
292
+ <tbody>
293
+ <tr>
294
+ <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>
295
+ </tr>
296
+ </tbody>
297
+ <tfoot>
298
+ <tr>
299
+ <td align="center" size="13px" colspan="7">
300
+ <img src="https://raw.githubusercontent.com/all-contributors/all-contributors-cli/1b8533af435da9854653492b1327a23a4dbd0a10/assets/logo-small.svg">
301
+ <a href="https://all-contributors.js.org/docs/en/bot/usage">Add your contributions</a>
302
+ </img>
303
+ </td>
304
+ </tr>
305
+ </tfoot>
306
+ </table>
307
+
308
+ <!-- markdownlint-restore -->
309
+ <!-- prettier-ignore-end -->
310
+
311
+ <!-- ALL-CONTRIBUTORS-LIST:END -->
312
+
313
+ This project follows the [all-contributors][all-contributors] specification.
314
+ Contributions of any kind welcome!
315
+
316
+ [emojis]: https://github.com/all-contributors/all-contributors#emoji-key
317
+
318
+ [all-contributors]: https://github.com/all-contributors/all-contributors
319
+
320
+ ## Acknowledgements
321
+
322
+ Massive thanks to the [Qwik Team][qwik-team] and the whole community for their efforts to build Qwik and for
323
+ the [inspiration][qwik-baseline] on how to create a testing library for Qwik.
324
+
325
+ Thanks to the [Testing Library Team][tl-team] for a great set of tools to build better products, confidently, and
326
+ qwikly.
327
+
328
+ [qwik-team]: https://github.com/QwikDev/qwik/
329
+
330
+ [qwik-baseline]: https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/testing
331
+
332
+ [tl-team]: https://testing-library.com
package/package.json CHANGED
@@ -1,7 +1,9 @@
1
1
  {
2
2
  "name": "@noma.to/qwik-testing-library",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
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",
5
7
  "main": "./lib/index.qwik.mjs",
6
8
  "qwik": "./lib/index.qwik.mjs",
7
9
  "types": "./lib-types/index.d.ts",