File tree 5 files changed +34
-8
lines changed
5 files changed +34
-8
lines changed Original file line number Diff line number Diff line change 160
160
" doc" ,
161
161
" example"
162
162
]
163
+ },
164
+ {
165
+ "login" : " dfcook" ,
166
+ "name" : " Daniel Cook" ,
167
+ "avatar_url" : " https://avatars3.githubusercontent.com/u/10348212?v=4" ,
168
+ "profile" : " https://github.com/dfcook" ,
169
+ "contributions" : [
170
+ " code" ,
171
+ "doc,
172
+ " test"
173
+ ]
163
174
}
164
175
]
165
176
}
Original file line number Diff line number Diff line change @@ -83,6 +83,7 @@ when a real user uses it.
83
83
* [ Using other assertion libraries] ( #using-other-assertion-libraries )
84
84
* [ ` TextMatch ` ] ( #textmatch )
85
85
* [ ` query ` APIs] ( #query-apis )
86
+ * [ ` bindElementToQueries ` ] ( #bindElementToQueries )
86
87
* [ Debugging] ( #debugging )
87
88
* [ Implementations] ( #implementations )
88
89
* [ FAQ] ( #faq )
@@ -468,6 +469,12 @@ expect(submitButton).toBeNull() // it doesn't exist
468
469
expect(submitButton).not.toBeInTheDOM()
469
470
` ` `
470
471
472
+ ## ` bindElementToQueries `
473
+
474
+ ` bindElementToQueries ` takes a DOM element and binds it to the raw query functions , allowing them
475
+ to be used without specifying a container . It is the recommended approach for libraries built on this API
476
+ and is in use in ` react-testing-library ` and ` vue-testing-library ` .
477
+
471
478
## Debugging
472
479
473
480
When you use any ` get ` calls in your test cases , the current state of the ` container `
Original file line number Diff line number Diff line change 1
- import * as queries from '../../queries'
1
+ import { bindElementToQueries } from '../../bind-element-to- queries'
2
2
3
3
function render ( html ) {
4
4
const container = document . createElement ( 'div' )
5
5
container . innerHTML = html
6
- const containerQueries = Object . entries ( queries ) . reduce (
7
- ( helpers , [ key , fn ] ) => {
8
- helpers [ key ] = fn . bind ( null , container )
9
- return helpers
10
- } ,
11
- { } ,
12
- )
6
+ const containerQueries = bindElementToQueries ( container )
13
7
return { container, ...containerQueries }
14
8
}
15
9
Original file line number Diff line number Diff line change
1
+ import * as queries from './queries'
2
+
3
+ function bindElementToQueries ( element ) {
4
+ return Object . entries ( queries ) . reduce (
5
+ ( helpers , [ key , fn ] ) => {
6
+ helpers [ key ] = fn . bind ( null , element )
7
+ return helpers
8
+ } ,
9
+ { } ,
10
+ )
11
+ }
12
+
13
+ export { bindElementToQueries }
Original file line number Diff line number Diff line change @@ -9,3 +9,4 @@ export * from './wait'
9
9
export * from './wait-for-element'
10
10
export * from './matches'
11
11
export * from './events'
12
+ export * from './bind-element-to-queries'
You can’t perform that action at this time.
0 commit comments