File tree Expand file tree Collapse file tree 5 files changed +34
-8
lines changed Expand file tree Collapse file tree 5 files changed +34
-8
lines changed Original file line number Diff line number Diff line change 160160 " doc" ,
161161 " example"
162162 ]
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+ ]
163174 }
164175 ]
165176}
Original file line number Diff line number Diff line change @@ -83,6 +83,7 @@ when a real user uses it.
8383 * [ Using other assertion libraries] ( #using-other-assertion-libraries )
8484* [ ` TextMatch ` ] ( #textmatch )
8585* [ ` query ` APIs] ( #query-apis )
86+ * [ ` bindElementToQueries ` ] ( #bindElementToQueries )
8687* [ Debugging] ( #debugging )
8788* [ Implementations] ( #implementations )
8889* [ FAQ] ( #faq )
@@ -468,6 +469,12 @@ expect(submitButton).toBeNull() // it doesn't exist
468469expect(submitButton).not.toBeInTheDOM()
469470` ` `
470471
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+
471478## Debugging
472479
473480When 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'
22
33function render ( html ) {
44 const container = document . createElement ( 'div' )
55 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 )
137 return { container, ...containerQueries }
148}
159
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'
99export * from './wait-for-element'
1010export * from './matches'
1111export * from './events'
12+ export * from './bind-element-to-queries'
You can’t perform that action at this time.
0 commit comments