Skip to content

Commit e596b05

Browse files
authored
feat: more tsx tabs in RTL setup doc (#828)
* feat: more tsx tabs in RTL setup doc * fix: import types + remove ts commonjs example * fix: remove redundant Omit type import * fix: omit wrapper instead of queries
1 parent e6ef8e4 commit e596b05

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

docs/react-testing-library/setup.mdx

+29-3
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,10 @@ const AllTheProviders: FC = ({ children }) => {
9696

9797
const customRender = (
9898
ui: ReactElement,
99-
options?: Omit<RenderOptions, 'queries'>
99+
options?: Omit<RenderOptions, 'wrapper'>
100100
) => render(ui, { wrapper: AllTheProviders, ...options })
101101

102102
export * from '@testing-library/react'
103-
104103
export { customRender as render }
105104
```
106105

@@ -194,7 +193,12 @@ passing a [`queries`](api.mdx#render-options) option.
194193
If you want to add custom queries globally, you can do this by defining a custom
195194
render method:
196195

197-
```js title="test-utils.js"
196+
<Tabs groupId="test-utils" defaultValue="jsx" values={[ {label: 'Javascript',
197+
value: 'jsx'}, {label: 'Typescript', value: 'tsx'}, ]}>
198+
199+
<TabItem value="jsx">
200+
201+
```jsx title="test-utils.js"
198202
// test-utils.js
199203
import { render, queries } from '@testing-library/react'
200204
import * as customQueries from './custom-queries'
@@ -209,6 +213,28 @@ export * from '@testing-library/react'
209213
export { customRender as render }
210214
```
211215

216+
</TabItem>
217+
218+
<TabItem value="tsx">
219+
220+
```tsx title="test-utils.ts"
221+
// test-utils.ts
222+
import { render, queries, RenderOptions } from '@testing-library/react'
223+
import * as customQueries from './custom-queries'
224+
import { ReactElement } from 'react'
225+
226+
const customRender = (
227+
ui: ReactElement,
228+
options?: Omit<RenderOptions, 'queries'>
229+
) => render(ui, { queries: { ...queries, ...customQueries }, ...options })
230+
231+
export * from '@testing-library/react'
232+
export { customRender as render }
233+
```
234+
235+
</TabItem>
236+
</Tabs>
237+
212238
You can then use your custom queries as you would any other query:
213239

214240
```js

0 commit comments

Comments
 (0)