File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
docs/react-testing-library Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -144,6 +144,35 @@ module.exports = {
144
144
145
145
</details >
146
146
147
+ <details >
148
+ <summary >Modify queries globally with custom render</summary >
149
+
150
+ You can override and append queries to the render function by passing a [ ` queries ` ] ( api.md#render-options ) option.
151
+
152
+ If you want to add custom queries globally, you can do this by defining a custom render method:
153
+
154
+ ``` js
155
+ // test-utils.js
156
+ import { render , queries , queryHelpers } from ' @testing-library/react'
157
+
158
+ const customQueries = {
159
+ getByDataCy: queryHelpers .queryByAttribute .bind (
160
+ null ,
161
+ ' data-cy'
162
+ ),
163
+ };
164
+
165
+ const customRender = (ui , options ) =>
166
+ render (ui, { queries: { ... queries, ... customQueries } })
167
+
168
+ // re-export everything
169
+ export * from ' @testing-library/react'
170
+
171
+ // override render method
172
+ export { customRender as render }
173
+ ```
174
+ </details >
175
+
147
176
### Configuring Jest with Test Utils
148
177
149
178
To make your custom test file accessible in your Jest test files without using
You can’t perform that action at this time.
0 commit comments