Skip to content

Commit 349c957

Browse files
authored
Merge pull request #40 from solidjs/router-setup
new location option to setup router
2 parents d1c252c + 47bd342 commit 349c957

7 files changed

Lines changed: 388 additions & 342 deletions

File tree

README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,22 @@ const results = render(<YourComponent />, options);
7474
const results = render(() => <YourComponent />, options);
7575
```
7676

77-
⚠️ Solid.js does *not* rerender, it merely executes side effects triggered by reactive state that change the DOM, therefore there is no rerender method. You can use global signals to manipulate your test component in a way that causes it to update.
77+
⚠️ Solid.js does *not* re-render, it merely executes side effects triggered by reactive state that change the DOM, therefore there is no `rerender` method. You can use global signals to manipulate your test component in a way that causes it to update.
7878

79-
Solid.js' reactive changes are pretty instantaneous, so there is rarely need to use `waitFor(…)` or `await findByRole(…)` - with the exception of transitions and Suspense.
79+
Solid.js reactive changes are pretty instantaneous, so there is rarely need to use `waitFor(…)` or `await findByRole(…)`, except for transitions, suspense and router navigation.
80+
81+
⚠️ In extension of the original API, this testing library supports a convenient `location` option that will set up a router with memory integration pointing at a certain path. Since setting the path is not instantaneous, you need to use asynchronous queries after employing it:
82+
83+
```tsx
84+
const App = () => (
85+
<Routes>
86+
<Route path="/ids/:id" component={() => <p>Id: {useParams()?.id}</p>} />
87+
<Route path="/" component={() => <p>Start</p>} />
88+
</Routes>
89+
);
90+
const { findByText } = render(() => <App />, { location: "ids/1234" });
91+
expect(findByText("Id: 1234")).not.toBeFalsy();
92+
```
8093

8194
⚠️ 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.
8295

@@ -168,7 +181,7 @@ If you find any issues, please [check on the issues page](https://github.com/sol
168181

169182
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.
170183

171-
## Acknowledgment
184+
## Acknowledgement
172185

173186
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).
174187

0 commit comments

Comments
 (0)