You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You want to write tests for your Solid components so that they avoid including implementation
33
-
details, and are maintainable in the long run.
33
+
You want to write tests for your Solid components so that they avoid including implementation details, and are maintainable in the long run.
34
+
34
35
35
36
## The Solution
36
37
@@ -52,10 +53,12 @@ If you using Jest we recommend using [solid-jest](https://github.com/solidjs/sol
52
53
💡 If you are using Jest or vitest, you may also be interested in installing `@testing-library/jest-dom` so you can use
53
54
[the custom jest matchers](https://github.com/testing-library/jest-dom).
54
55
56
+
55
57
## Integration with Vite
56
58
57
59
A working Vite template setup with `solid-testing-library` and TypeScript support can be found [here](https://github.com/solidjs/solid-start/tree/main/examples/with-vitest).
58
60
61
+
59
62
## Docs
60
63
61
64
See the [docs](https://testing-library.com/docs/preact-testing-library/intro) over at the Testing Library website.
It allows running the effect inside a defined owner that is received as an optional second argument. This can be useful in combination with `renderHook`, which gives you an owner field in its result. The return value is a Promise with the value given to the `done()` callback. You can either await the result for further assertions or return it to your test runner.
177
180
181
+
178
182
## Issues
179
183
180
184
If you find any issues, please [check on the issues page](https://github.com/solidjs/solid-testing-library/issues) if they are already known. If not, opening an issue will be much appreciated, even more so if it contains a
@@ -185,6 +189,38 @@ If you find any issues, please [check on the issues page](https://github.com/sol
185
189
186
190
If you think you can fix an issue yourself, feel free to [open a pull-request](https://github.com/solidjs/solid-testing-library/pulls). If functionality changes, please don't forget to add or adapt tests.
187
191
192
+
193
+
### Known issues
194
+
195
+
If you are using [`vitest`](https://vitest.dev/), then tests might fail, because the packages `solid-js`, and `@solidjs/router` (if used) need to be loaded only once, and they could be loaded both through the internal `vite` server and through node. Typical bugs that happen because of this is that dispose is supposedly undefined, or the router could not be loaded.
196
+
197
+
There are three ways you could attempt to work around this problem. If they work depends on your version of `vitest`, which version of `node-js` and what package manager you use (some of them change the way node resolves modules):
198
+
199
+
```ts
200
+
// this is inside your vite(st) config:
201
+
{
202
+
test: {
203
+
deps: {
204
+
// 1nd way: remove the @solidjs/router part if you do not use it:
At the moment of writing this, the 1st way seems to be the most reliable for the default solid template. Solid-start's vite plugin might need a different configuration.
222
+
223
+
188
224
## Acknowledgement
189
225
190
226
Thanks goes to [Kent C. Dodds](https://kentcdodds.com/) and his colleagues for creating testing-library and to the creators of [preact-testing-library](https://github.com/testing-library/preact-testing-library).
0 commit comments