Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Jun 7, 2021
1 parent 2632aae commit 7d5ea52
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 88 deletions.
6 changes: 3 additions & 3 deletions src/__tests__/ariaAttributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ test('`selected: true` matches `aria-selected="true"` on supported roles', () =>
'selected-listbox-option',
])

expect(
getAllByRole('rowheader', {selected: true}).map(({id}) => id),
).toEqual(['selected-rowheader', 'selected-native-rowheader'])
expect(getAllByRole('rowheader', {selected: true}).map(({id}) => id)).toEqual(
['selected-rowheader', 'selected-native-rowheader'],
)

expect(getAllByRole('treeitem', {selected: true}).map(({id}) => id)).toEqual([
'selected-treeitem',
Expand Down
21 changes: 6 additions & 15 deletions src/__tests__/element-queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -1099,11 +1099,8 @@ test('getByText ignores script tags by default', () => {
})

test('get/query input element by current value', () => {
const {
getByDisplayValue,
queryByDisplayValue,
getByTestId,
} = renderIntoDocument(`
const {getByDisplayValue, queryByDisplayValue, getByTestId} =
renderIntoDocument(`
<div>
<input placeholder="name" type="text" data-testid="name" value="Mercury" />
</div>
Expand All @@ -1119,11 +1116,8 @@ test('get/query input element by current value', () => {
})

test('get/query select element by current value', () => {
const {
getByDisplayValue,
queryByDisplayValue,
getByTestId,
} = renderIntoDocument(`
const {getByDisplayValue, queryByDisplayValue, getByTestId} =
renderIntoDocument(`
<select id="state-select" data-testid="state">
<option value="">State</option>
<option value="AL">Alabama</option>
Expand All @@ -1141,11 +1135,8 @@ test('get/query select element by current value', () => {
})

test('get/query textarea element by current value', () => {
const {
getByDisplayValue,
queryByDisplayValue,
getByTestId,
} = renderIntoDocument(`
const {getByDisplayValue, queryByDisplayValue, getByTestId} =
renderIntoDocument(`
<textarea id="content-textarea" data-testid="content">
Hello
</textarea>
Expand Down
6 changes: 4 additions & 2 deletions src/get-user-code-frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ try {
const nodeRequire = module && module.require

readFileSync = nodeRequire.call(module, 'fs').readFileSync
codeFrameColumns = nodeRequire.call(module, '@babel/code-frame')
.codeFrameColumns
codeFrameColumns = nodeRequire.call(
module,
'@babel/code-frame',
).codeFrameColumns
chalk = nodeRequire.call(module, 'chalk')
} catch {
// We're in a browser environment
Expand Down
13 changes: 4 additions & 9 deletions src/queries/role.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ function queryAllByRole(

return matches(
computeAccessibleName(element, {
computedStyleSupportsPseudoElements: getConfig()
.computedStyleSupportsPseudoElements,
computedStyleSupportsPseudoElements:
getConfig().computedStyleSupportsPseudoElements,
}),
element,
name,
Expand Down Expand Up @@ -227,13 +227,8 @@ const queryAllByRoleWithSuggestions = wrapAllByQueryWithSuggestion(
queryAllByRole.name,
'queryAll',
)
const [
queryByRole,
getAllByRole,
getByRole,
findAllByRole,
findByRole,
] = buildQueries(queryAllByRole, getMultipleError, getMissingError)
const [queryByRole, getAllByRole, getByRole, findAllByRole, findByRole] =
buildQueries(queryAllByRole, getMultipleError, getMissingError)

export {
queryByRole,
Expand Down
9 changes: 2 additions & 7 deletions src/queries/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,8 @@ const queryAllByTextWithSuggestions = wrapAllByQueryWithSuggestion(
'queryAll',
)

const [
queryByText,
getAllByText,
getByText,
findAllByText,
findByText,
] = buildQueries(queryAllByText, getMultipleError, getMissingError)
const [queryByText, getAllByText, getByText, findAllByText, findByText] =
buildQueries(queryAllByText, getMultipleError, getMissingError)

export {
queryByText,
Expand Down
9 changes: 2 additions & 7 deletions src/queries/title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,8 @@ const queryAllByTitleWithSuggestions = wrapAllByQueryWithSuggestion(
'queryAll',
)

const [
queryByTitle,
getAllByTitle,
getByTitle,
findAllByTitle,
findByTitle,
] = buildQueries(queryAllByTitle, getMultipleError, getMissingError)
const [queryByTitle, getAllByTitle, getByTitle, findAllByTitle, findByTitle] =
buildQueries(queryAllByTitle, getMultipleError, getMissingError)

export {
queryByTitle,
Expand Down
74 changes: 36 additions & 38 deletions src/query-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,49 +100,47 @@ function makeFindQuery(getter) {
}
}

const wrapSingleQueryWithSuggestion = (query, queryAllByName, variant) => (
container,
...args
) => {
const element = query(container, ...args)
const [{suggest = getConfig().throwSuggestions} = {}] = args.slice(-1)
if (element && suggest) {
const suggestion = getSuggestedQuery(element, variant)
if (suggestion && !queryAllByName.endsWith(suggestion.queryName)) {
throw getSuggestionError(suggestion.toString(), container)
const wrapSingleQueryWithSuggestion =
(query, queryAllByName, variant) =>
(container, ...args) => {
const element = query(container, ...args)
const [{suggest = getConfig().throwSuggestions} = {}] = args.slice(-1)
if (element && suggest) {
const suggestion = getSuggestedQuery(element, variant)
if (suggestion && !queryAllByName.endsWith(suggestion.queryName)) {
throw getSuggestionError(suggestion.toString(), container)
}
}
}

return element
}
return element
}

const wrapAllByQueryWithSuggestion = (query, queryAllByName, variant) => (
container,
...args
) => {
const els = query(container, ...args)

const [{suggest = getConfig().throwSuggestions} = {}] = args.slice(-1)
if (els.length && suggest) {
// get a unique list of all suggestion messages. We are only going to make a suggestion if
// all the suggestions are the same
const uniqueSuggestionMessages = [
...new Set(
els.map(element => getSuggestedQuery(element, variant)?.toString()),
),
]

if (
// only want to suggest if all the els have the same suggestion.
uniqueSuggestionMessages.length === 1 &&
!queryAllByName.endsWith(getSuggestedQuery(els[0], variant).queryName)
) {
throw getSuggestionError(uniqueSuggestionMessages[0], container)
const wrapAllByQueryWithSuggestion =
(query, queryAllByName, variant) =>
(container, ...args) => {
const els = query(container, ...args)

const [{suggest = getConfig().throwSuggestions} = {}] = args.slice(-1)
if (els.length && suggest) {
// get a unique list of all suggestion messages. We are only going to make a suggestion if
// all the suggestions are the same
const uniqueSuggestionMessages = [
...new Set(
els.map(element => getSuggestedQuery(element, variant)?.toString()),
),
]

if (
// only want to suggest if all the els have the same suggestion.
uniqueSuggestionMessages.length === 1 &&
!queryAllByName.endsWith(getSuggestedQuery(els[0], variant).queryName)
) {
throw getSuggestionError(uniqueSuggestionMessages[0], container)
}
}
}

return els
}
return els
}

function buildQueries(queryAllBy, getMultipleError, getMissingError) {
const queryBy = wrapSingleQueryWithSuggestion(
Expand Down
4 changes: 2 additions & 2 deletions src/role-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ function prettyRoles(dom, {hidden}) {
const elementsString = elements
.map(el => {
const nameString = `Name "${computeAccessibleName(el, {
computedStyleSupportsPseudoElements: getConfig()
.computedStyleSupportsPseudoElements,
computedStyleSupportsPseudoElements:
getConfig().computedStyleSupportsPseudoElements,
})}":\n`
const domString = prettyDOM(el.cloneNode(false))
return `${nameString}${domString}`
Expand Down
4 changes: 2 additions & 2 deletions src/suggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ export function getSuggestedQuery(element, variant = 'get', method) {
return makeSuggestion('Role', element, role, {
variant,
name: computeAccessibleName(element, {
computedStyleSupportsPseudoElements: getConfig()
.computedStyleSupportsPseudoElements,
computedStyleSupportsPseudoElements:
getConfig().computedStyleSupportsPseudoElements,
}),
})
}
Expand Down
6 changes: 3 additions & 3 deletions types/role-helpers.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export function logRoles(container: HTMLElement): string
export function getRoles(
container: HTMLElement,
): {[index: string]: HTMLElement[]}
export function getRoles(container: HTMLElement): {
[index: string]: HTMLElement[]
}
/**
* https://testing-library.com/docs/dom-testing-library/api-helpers#isinaccessible
*/
Expand Down

0 comments on commit 7d5ea52

Please sign in to comment.