diff --git a/src/__tests__/query-helper.js b/src/__tests__/query-helper.js new file mode 100644 index 00000000..7e53ab03 --- /dev/null +++ b/src/__tests__/query-helper.js @@ -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]) +}) diff --git a/src/query-helpers.js b/src/query-helpers.js index 3e493699..7fcc6bd9 100644 --- a/src/query-helpers.js +++ b/src/query-helpers.js @@ -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, ) @@ -82,6 +86,7 @@ function buildQueries(queryAllBy, getMultipleError, getMissingError) { } export { + getElementError, getMultipleElementsFoundError, queryAllByAttribute, queryByAttribute,