Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ when a real user uses it.
* [TextMatch Examples](#textmatch-examples)
* [`query` APIs](#query-apis)
* [`queryAll` and `getAll` APIs](#queryall-and-getall-apis)
* [`bindElementToQueries`](#bindelementtoqueries)
* [`getQueriesForElement`](#getqueriesforelement)
* [Debugging](#debugging)
* [`prettyDOM`](#prettydom)
* [Implementations](#implementations)
Expand Down Expand Up @@ -640,9 +640,9 @@ expect(submitButtons).toHaveLength(3) // expect 3 elements
expect(submitButtons[0]).toBeInTheDOM()
```

## `bindElementToQueries`
## `getQueriesForElement`

`bindElementToQueries` takes a DOM element and binds it to the raw query functions, allowing them
`getQueriesForElement` takes a DOM element and binds it to the raw query functions, allowing them
to be used without specifying a container. It is the recommended approach for libraries built on this API
and is in use in `react-testing-library` and `vue-testing-library`.

Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/helpers/test-utils.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {bindElementToQueries} from '../../bind-element-to-queries'
import {getQueriesForElement} from '../../get-queries-for-element'

function render(html) {
const container = document.createElement('div')
container.innerHTML = html
const containerQueries = bindElementToQueries(container)
const containerQueries = getQueriesForElement(container)
return {container, ...containerQueries}
}

Expand Down
13 changes: 0 additions & 13 deletions src/bind-element-to-queries.js

This file was deleted.

10 changes: 10 additions & 0 deletions src/get-queries-for-element.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as queries from './queries'

function getQueriesForElement(element) {
return Object.entries(queries).reduce((helpers, [key, fn]) => {
helpers[key] = fn.bind(null, element)
return helpers
}, {})
}

export {getQueriesForElement}
7 changes: 6 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {getQueriesForElement} from './get-queries-for-element'
import * as queries from './queries'

// exporting on the queries namespace as a convenience
Expand All @@ -10,5 +11,9 @@ export * from './wait-for-element'
export * from './matches'
export * from './get-node-text'
export * from './events'
export * from './bind-element-to-queries'
export * from './get-queries-for-element'
export * from './pretty-dom'

// The original name of bindElementToQueries was weird
// The new name is better. Remove this in the next major version bump.
export {getQueriesForElement as bindElementToQueries}