Skip to content

Commit

Permalink
add tests or query builder
Browse files Browse the repository at this point in the history
  • Loading branch information
mzdunek93 committed May 15, 2020
1 parent 76a6886 commit 5a9be5f
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion types/__tests__/type-tests.ts
Expand Up @@ -2,9 +2,12 @@ import {
fireEvent,
isInaccessible,
queries,
buildQueries,
queryAllByAttribute,
screen,
waitFor,
waitForElementToBeRemoved,
MatcherOptions,
} from '../index'

const {
Expand Down Expand Up @@ -42,6 +45,42 @@ async function testQueries() {
await screen.findAllByText('bar', undefined, {timeout: 10})
}

async function testQueryHelpers() {
const element = document.createElement('div')
const includesAutomationId = (content: string, automationId: string) =>
content.split(/\s+/).some(id => id === automationId)
const queryAllByAutomationId = (
container: HTMLElement,
automationId: string | string[],
options?: MatcherOptions,
) =>
queryAllByAttribute(
'testId',
container,
content =>
Array.isArray(automationId)
? automationId.every(id => includesAutomationId(content, id))
: includesAutomationId(content, automationId),
options,
)
const [
queryByAutomationId,
getAllByAutomationId,
getByAutomationId,
findAllByAutomationId,
findByAutomationId,
] = buildQueries(
queryAllByAutomationId,
() => 'Multiple Error',
() => 'Missing Error',
)
queryByAutomationId(element, 'id')
getAllByAutomationId(element, 'id')
getByAutomationId(element, ['id', 'automationId'])
findAllByAutomationId(element, 'id', {}, {timeout: 1000})
findByAutomationId(element, 'id', {}, {timeout: 1000})
}

async function testByRole() {
const element = document.createElement('button')
element.setAttribute('aria-hidden', 'true')
Expand Down Expand Up @@ -116,7 +155,11 @@ async function testWaitFors() {

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

await waitForElementToBeRemoved(() => getByText(element, 'apple'), {interval: 3000, container: element, timeout: 5000})
await waitForElementToBeRemoved(() => getByText(element, 'apple'), {
interval: 3000,
container: element,
timeout: 5000,
})
await waitForElementToBeRemoved(getByText(element, 'apple'))
await waitForElementToBeRemoved(getAllByText(element, 'apple'))
}

0 comments on commit 5a9be5f

Please sign in to comment.