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
Copy file name to clipboardExpand all lines: docs/usage/WritingTests.mdx
+9-111Lines changed: 9 additions & 111 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -40,20 +40,20 @@ For background on why we recommend integration-style tests, see:
40
40
41
41
### Test Runners
42
42
43
-
**Redux can be tested with any test runner**, since it's just plain JavaScript. One common option is [Jest](https://jestjs.io/), a widely used test runner that comes with Create-React-App, and is used by the Redux library repos. If you're using [Vite](https://vitejs.dev/) to build your project, you may be using [Vitest](https://vitest.dev/)as your test runner.
43
+
**Redux can be tested with any test runner**, since it's just plain JavaScript. An increasingly common choice is [Vitest](https://vitest.dev/) (used by the Redux library repos), though [Jest](https://jestjs.io/)is still used widely.
44
44
45
-
Typically, your test runner needs to be configured to compile JavaScript/TypeScript syntax. If you're going to be testing UI components, you will likely need to configure the test runner to use [JSDOM](https://github.com/jsdom/jsdom) to provide a mock DOM environment.
45
+
Typically, your test runner needs to be configured to compile JavaScript/TypeScript syntax. If you're going to be testing UI components**without a browser**, you will likely need to configure the test runner to use [JSDOM](https://github.com/jsdom/jsdom) to provide a mock DOM environment.
46
46
47
-
The examples in this page will assume you're using Jest, but the same patterns apply no matter what test runner you're using.
47
+
The examples in this page will assume you're using Vitest, but the same patterns apply no matter what test runner you're using.
48
48
49
49
See these resources for typical test runner configuration instructions:
// This type interface extends the default options for render from RTL, as well
346
344
// as allows the user to specify other things such as initialState, store.
@@ -372,113 +370,12 @@ export function renderWithProviders(
372
370
}
373
371
```
374
372
375
-
In this example, we're directly importing the same slice reducers that the real app uses to create the store. It may be helpful to create a reusable `setupStore` function that does the actual store creation with the right options and configuration, and use that in the custom render function instead.
The actual test files should use the custom `render` function to actually render our Redux-connected components. If the code that we're testing involves making network requests, we should also configure MSW to mock the expected requests with appropriate test data.
0 commit comments