@@ -78,7 +78,8 @@ export { customRender as render }
78
78
```
79
79
80
80
``` tsx title="test-utils.tsx"
81
- import React , { FC } from ' react'
81
+ import React , { FC , ReactElement } from ' react'
82
+ import { Omit } from ' react-redux'
82
83
import { render , RenderOptions } from ' @testing-library/react'
83
84
import { ThemeProvider } from ' my-ui-lib'
84
85
import { TranslationProvider } from ' my-i18n-lib'
@@ -100,7 +101,6 @@ const customRender = (
100
101
) => render (ui , { wrapper: AllTheProviders , ... options })
101
102
102
103
export * from ' @testing-library/react'
103
-
104
104
export { customRender as render }
105
105
```
106
106
@@ -119,12 +119,7 @@ export { customRender as render }
119
119
120
120
You can use CommonJS modules instead of ES modules, which should work in Node:
121
121
122
- <Tabs groupId = " test-utils" defaultValue = " jsx" values = { [ {label: ' Javascript' ,
123
- value: ' jsx' }, {label: ' Typescript' , value: ' tsx' }, ]} >
124
-
125
- <TabItem value = " jsx" >
126
-
127
- ``` jsx title="test-utils.js"
122
+ ``` js title="test-utils.js"
128
123
const rtl = require (' @testing-library/react' )
129
124
130
125
const customRender = (ui , options ) =>
@@ -139,32 +134,6 @@ module.exports = {
139
134
}
140
135
```
141
136
142
- </TabItem >
143
-
144
- <TabItem value = " tsx" >
145
-
146
- ``` tsx title="test-utils.ts"
147
- const rtl = require (' @testing-library/react' )
148
-
149
- const customRender = (
150
- ui : ReactElement ,
151
- options ? : Omit <RenderOptions , ' queries' >
152
- ) =>
153
- rtl .render (ui , {
154
- myDefaultOption: ' something' ,
155
- ... options ,
156
- })
157
-
158
- module .exports = {
159
- ... rtl ,
160
- render: customRender ,
161
- }
162
- ```
163
-
164
- </TabItem >
165
-
166
- </Tabs >
167
-
168
137
### Add custom queries
169
138
170
139
> ** Note**
@@ -251,18 +220,17 @@ export { customRender as render }
251
220
252
221
``` tsx title="test-utils.ts"
253
222
// test-utils.ts
254
- import { render , queries } from ' @testing-library/react'
223
+ import { render , queries , RenderOptions } from ' @testing-library/react'
255
224
import * as customQueries from ' ./custom-queries'
225
+ import { ReactElement } from ' react'
226
+ import { Omit } from ' react-redux'
256
227
257
228
const customRender = (
258
229
ui : ReactElement ,
259
230
options ? : Omit <RenderOptions , ' queries' >
260
231
) => render (ui , { queries: { ... queries , ... customQueries }, ... options })
261
232
262
- // re-export everything
263
233
export * from ' @testing-library/react'
264
-
265
- // override render method
266
234
export { customRender as render }
267
235
```
268
236
0 commit comments