Skip to content

Commit 67370d0

Browse files
fix: queryHelpers.getElementError is not a function (#510)
* feat: redefine getElementError * test: add test * Update src/query-helpers.js Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
1 parent 7741721 commit 67370d0

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/__tests__/query-helper.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import * as queryHelpers from '../query-helpers'
2+
import {configure, getConfig} from '../config'
3+
4+
const originalConfig = getConfig()
5+
beforeEach(() => {
6+
configure(originalConfig)
7+
})
8+
9+
test('should delegate to config.getElementError', () => {
10+
const getElementError = jest.fn()
11+
configure({getElementError})
12+
13+
const message = 'test Message'
14+
const container = {} // dummy
15+
16+
queryHelpers.getElementError(message, container)
17+
expect(getElementError.mock.calls[0]).toEqual([message, container])
18+
})

src/query-helpers.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ import {fuzzyMatches, matches, makeNormalizer} from './matches'
22
import {waitFor} from './wait-for'
33
import {getConfig} from './config'
44

5+
function getElementError(message, container) {
6+
return getConfig().getElementError(message, container)
7+
}
8+
59
function getMultipleElementsFoundError(message, container) {
6-
return getConfig().getElementError(
10+
return getElementError(
711
`${message}\n\n(If this is intentional, then use the \`*AllBy*\` variant of the query (like \`queryAllByText\`, \`getAllByText\`, or \`findAllByText\`)).`,
812
container,
913
)
@@ -82,6 +86,7 @@ function buildQueries(queryAllBy, getMultipleError, getMissingError) {
8286
}
8387

8488
export {
89+
getElementError,
8590
getMultipleElementsFoundError,
8691
queryAllByAttribute,
8792
queryByAttribute,

0 commit comments

Comments
 (0)