Skip to content

fix: queryHelpers.getElementError is not a function #510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 30, 2020
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
18 changes: 18 additions & 0 deletions src/__tests__/query-helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as queryHelpers from '../query-helpers'
import {configure, getConfig} from '../config'

const originalConfig = getConfig()
beforeEach(() => {
configure(originalConfig)
})

test('should delegate to config.getElementError', () => {
const getElementError = jest.fn()
configure({getElementError})

const message = 'test Message'
const container = {} // dummy

queryHelpers.getElementError(message, container)
expect(getElementError.mock.calls[0]).toEqual([message, container])
})
7 changes: 6 additions & 1 deletion src/query-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ import {fuzzyMatches, matches, makeNormalizer} from './matches'
import {waitFor} from './wait-for'
import {getConfig} from './config'

function getElementError(message, container) {
return getConfig().getElementError(message, container)
}

function getMultipleElementsFoundError(message, container) {
return getConfig().getElementError(
return getElementError(
`${message}\n\n(If this is intentional, then use the \`*AllBy*\` variant of the query (like \`queryAllByText\`, \`getAllByText\`, or \`findAllByText\`)).`,
container,
)
Expand Down Expand Up @@ -82,6 +86,7 @@ function buildQueries(queryAllBy, getMultipleError, getMissingError) {
}

export {
getElementError,
getMultipleElementsFoundError,
queryAllByAttribute,
queryByAttribute,
Expand Down