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
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