Skip to content

Commit e82777d

Browse files
author
Alex Lohr
committed
version bump, added test, reduced testing config, docs
1 parent b1ba1ea commit e82777d

File tree

5 files changed

+177
-322
lines changed

5 files changed

+177
-322
lines changed

README.md

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ If you using Jest we recommend using [solid-jest](https://github.com/solidjs/sol
5656

5757
## Integration with Vite
5858

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).
59+
A working Vite template setup with `solid-testing-library` and TypeScript support can be found [for classic solid](https://github.com/solidjs/templates/tree/main/ts-vitest) and [for solid-start](https://github.com/solidjs/solid-start/tree/main/examples/with-vitest).
6060

6161

6262
## Docs
@@ -98,7 +98,7 @@ it('uses params', async () => {
9898

9999
It uses `@solidjs/router`, so if you want to use a different router, you should consider the `wrapper` option instead. If you attempt to use this without having the package installed, you will receive an error message.
100100

101-
⚠️ Solid.js external reactive state does not require any DOM elements to run in, so our `renderHook` call has no `container`, `baseElement` or queries in its options or return value. Instead, it has an `owner` to be used with [`runWithOwner`](https://www.solidjs.com/docs/latest/api#runwithowner) if required. It also exposes a `cleanup` function, though this is already automatically called after the test is finished.
101+
⚠️ Solid.js external reactive state does not require any DOM elements to run in, so our `renderHook` call to test hooks in the context of a component (if your hook does not require the context of a component, `createRoot` should suffice to test the reactive behavior; for convenience, we also have `createEffect`, which is described later) has no `container`, `baseElement` or queries in its options or return value. Instead, it has an `owner` to be used with [`runWithOwner`](https://www.solidjs.com/docs/latest/api#runwithowner) if required. It also exposes a `cleanup` function, though this is already automatically called after the test is finished.
102102

103103
```ts
104104
function renderHook<Args extends any[], Result>(
@@ -181,45 +181,22 @@ It allows running the effect inside a defined owner that is received as an optio
181181

182182
## Issues
183183

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
184+
If you find any issues *with this library*, 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
185185

186186
- short description
187187
- minimal reproduction code
188188
- list of possible workarounds, if there are any
189189

190190
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.
191191

192+
Please keep in mind that not all issues related to testing Solid.js code are directly related to this library. In some cases, the culprit might be [Solid's vite plugin](https://github.com/solidjs/vite-plugin-solid) or [Vitest](https://github.com/vitest-dev/vitest) instead. Posting the issue to the correct project will speed up fixing it; if in doubt, you can ask [on our discord](https://discord.com/invite/solidjs).
193+
192194

193195
### Known issues
194196

195197
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.
196198

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:
205-
inline: [/solid-js/, /@solidjs\/router/],
206-
// 2st way
207-
registerNodeLoader: false,
208-
},
209-
// 3rd way: alias the resolution
210-
resolve: {
211-
alias: {
212-
"solid-js": "node_modules/solid-js/dist/dev.js",
213-
// only needed if the router is used:
214-
"@solidjs/router": "node_modules/@solidjs/router/index.jsx",
215-
},
216-
},
217-
},
218-
}
219-
```
220-
221-
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-
199+
Since version 2.8.2, our vite plugin has gained the capability to configure everything for testing, so you should only need extra configuration for globals, coverage, etc.
223200

224201
## Acknowledgement
225202

0 commit comments

Comments
 (0)