Skip to content

Commit 5a9be5f

Browse files
committed
add tests or query builder
1 parent 76a6886 commit 5a9be5f

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

types/__tests__/type-tests.ts

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ import {
22
fireEvent,
33
isInaccessible,
44
queries,
5+
buildQueries,
6+
queryAllByAttribute,
57
screen,
68
waitFor,
79
waitForElementToBeRemoved,
10+
MatcherOptions,
811
} from '../index'
912

1013
const {
@@ -42,6 +45,42 @@ async function testQueries() {
4245
await screen.findAllByText('bar', undefined, {timeout: 10})
4346
}
4447

48+
async function testQueryHelpers() {
49+
const element = document.createElement('div')
50+
const includesAutomationId = (content: string, automationId: string) =>
51+
content.split(/\s+/).some(id => id === automationId)
52+
const queryAllByAutomationId = (
53+
container: HTMLElement,
54+
automationId: string | string[],
55+
options?: MatcherOptions,
56+
) =>
57+
queryAllByAttribute(
58+
'testId',
59+
container,
60+
content =>
61+
Array.isArray(automationId)
62+
? automationId.every(id => includesAutomationId(content, id))
63+
: includesAutomationId(content, automationId),
64+
options,
65+
)
66+
const [
67+
queryByAutomationId,
68+
getAllByAutomationId,
69+
getByAutomationId,
70+
findAllByAutomationId,
71+
findByAutomationId,
72+
] = buildQueries(
73+
queryAllByAutomationId,
74+
() => 'Multiple Error',
75+
() => 'Missing Error',
76+
)
77+
queryByAutomationId(element, 'id')
78+
getAllByAutomationId(element, 'id')
79+
getByAutomationId(element, ['id', 'automationId'])
80+
findAllByAutomationId(element, 'id', {}, {timeout: 1000})
81+
findByAutomationId(element, 'id', {}, {timeout: 1000})
82+
}
83+
4584
async function testByRole() {
4685
const element = document.createElement('button')
4786
element.setAttribute('aria-hidden', 'true')
@@ -116,7 +155,11 @@ async function testWaitFors() {
116155

117156
element.innerHTML = '<span>apple</span>'
118157

119-
await waitForElementToBeRemoved(() => getByText(element, 'apple'), {interval: 3000, container: element, timeout: 5000})
158+
await waitForElementToBeRemoved(() => getByText(element, 'apple'), {
159+
interval: 3000,
160+
container: element,
161+
timeout: 5000,
162+
})
120163
await waitForElementToBeRemoved(getByText(element, 'apple'))
121164
await waitForElementToBeRemoved(getAllByText(element, 'apple'))
122165
}

0 commit comments

Comments
 (0)