File tree Expand file tree Collapse file tree 2 files changed +52
-1
lines changed Expand file tree Collapse file tree 2 files changed +52
-1
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,12 @@ module.exports = {
50
50
}
51
51
```
52
52
53
+ > ** Note**
54
+ >
55
+ > Custom queries can be added to ` react-testing-library ` 's ` render ` method by
56
+ > adding ` queries ` to the options config object. See the render
57
+ > [ options] ( /docs/react-testing-library/api#render-options ) .
58
+
53
59
### Using other assertion libraries
54
60
55
61
If you're not using jest, you may be able to find a similar set of custom
@@ -105,13 +111,37 @@ in use in `react-testing-library` and `vue-testing-library`.
105
111
Example: To get the text 'hello' only within a section called 'messages', you
106
112
could do:
107
113
108
- ``` javascript
114
+ <!-- DOCUSAURUS_CODE_TABS-->
115
+
116
+ <!-- Native-->
117
+
118
+ ``` js
109
119
import { within } from ' dom-testing-library'
110
120
111
121
const { getByText } = within (document .getElementById (' messages' ))
112
122
const helloMessage = getByText (' hello' )
113
123
```
114
124
125
+ <!-- React-->
126
+
127
+ ``` js
128
+ import { render , within } from ' react-testing-library'
129
+
130
+ const { getByLabelText } = render (< MyComponent / > )
131
+ const signinModal = getByLabelText (' Sign In' )
132
+ within (signinModal).getByPlaceholderText (' Username' )
133
+ ```
134
+
135
+ <!-- Cypress-->
136
+
137
+ ``` js
138
+ cy .get (' form' ).within (() => {
139
+ cy .getByText (' Button Text' ).should (' be.disabled' )
140
+ })
141
+ ```
142
+
143
+ <!-- END_DOCUSAURUS_CODE_TABS-->
144
+
115
145
## Debugging
116
146
117
147
When you use any ` get ` calls in your test cases, the current state of the
Original file line number Diff line number Diff line change @@ -92,6 +92,27 @@ Pass a React Component as the `wrapper` option to have it rendered around the
92
92
inner element . This is most useful for creating reusable custom render functions
93
93
for common data providers . See [setup ](setup .md #custom - render ) for examples .
94
94
95
+ ### ` queries `
96
+
97
+ Queries to bind . Overrides the default set from ` dom-testing-library ` unless
98
+ merged .
99
+
100
+ ` ` ` js
101
+ // Example, a function to traverse table contents
102
+ import * as tableQueries from 'my-table-query-libary'
103
+ import queries from 'react-testing-library'
104
+
105
+ const { getByRowColumn, getByText } = render(<MyTable />, {
106
+ queries: { ...queries, ...tableQueries },
107
+ })
108
+ ` ` `
109
+
110
+ See [helpers ](../ api - helpers .md ) for guidance on using utility functions to
111
+ create custom queries .
112
+
113
+ Custom queries can also be added globally by following the
114
+ [custom render guide ](./ setup #custom - render ).
115
+
95
116
## ` render ` Result
96
117
97
118
The ` render ` method returns an object that has a few properties :
You can’t perform that action at this time.
0 commit comments