Skip to content

feat: more tsx tabs in RTL setup doc #828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions docs/react-testing-library/setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,10 @@ const AllTheProviders: FC = ({ children }) => {

const customRender = (
ui: ReactElement,
options?: Omit<RenderOptions, 'queries'>
options?: Omit<RenderOptions, 'wrapper'>
) => render(ui, { wrapper: AllTheProviders, ...options })

export * from '@testing-library/react'

export { customRender as render }
```

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

```js title="test-utils.js"
<Tabs groupId="test-utils" defaultValue="jsx" values={[ {label: 'Javascript',
value: 'jsx'}, {label: 'Typescript', value: 'tsx'}, ]}>

<TabItem value="jsx">

```jsx title="test-utils.js"
// test-utils.js
import { render, queries } from '@testing-library/react'
import * as customQueries from './custom-queries'
Expand All @@ -209,6 +213,28 @@ export * from '@testing-library/react'
export { customRender as render }
```

</TabItem>

<TabItem value="tsx">

```tsx title="test-utils.ts"
// test-utils.ts
import { render, queries, RenderOptions } from '@testing-library/react'
import * as customQueries from './custom-queries'
import { ReactElement } from 'react'

const customRender = (
ui: ReactElement,
options?: Omit<RenderOptions, 'queries'>
) => render(ui, { queries: { ...queries, ...customQueries }, ...options })

export * from '@testing-library/react'
export { customRender as render }
```

</TabItem>
</Tabs>

You can then use your custom queries as you would any other query:

```js
Expand Down