Skip to content

Commit 48cf918

Browse files
authored
Merge branch 'master' into pr/migrate_to_ts
2 parents f9b43d5 + 5bc9364 commit 48cf918

File tree

10 files changed

+284
-139
lines changed

10 files changed

+284
-139
lines changed

.all-contributorsrc

+29
Original file line numberDiff line numberDiff line change
@@ -1291,6 +1291,35 @@
12911291
"code",
12921292
"test"
12931293
]
1294+
},
1295+
{
1296+
"login": "johnjesse",
1297+
"name": "johnjessewood",
1298+
"avatar_url": "https://avatars1.githubusercontent.com/u/6839660?v=4",
1299+
"profile": "https://github.com/johnjesse",
1300+
"contributions": [
1301+
"bug",
1302+
"code"
1303+
]
1304+
},
1305+
{
1306+
"login": "AriPerkkio",
1307+
"name": "Ari Perkkiö",
1308+
"avatar_url": "https://avatars2.githubusercontent.com/u/14806298?v=4",
1309+
"profile": "https://codepen.io/ariperkkio/",
1310+
"contributions": [
1311+
"bug",
1312+
"code"
1313+
]
1314+
},
1315+
{
1316+
"login": "nathanforce",
1317+
"name": "Nathan Force",
1318+
"avatar_url": "https://avatars2.githubusercontent.com/u/6694194?v=4",
1319+
"profile": "https://github.com/nathanforce",
1320+
"contributions": [
1321+
"code"
1322+
]
12941323
}
12951324
],
12961325
"repoHost": "https://github.com"

.github/ISSUE_TEMPLATE/Question.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ and feature requests so we recommend not using this medium to ask them here 😁
1212

1313
## ❓ Support Forums
1414

15-
- Discord https://discord.gg/c6JN9fM
15+
- Discord https://discord.gg/testing-library
1616
- Stack Overflow
1717
https://stackoverflow.com/questions/tagged/react-testing-library
1818

README.md

+139-133
Large diffs are not rendered by default.

src/__node_tests__/index.js

+75
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,78 @@ test('byRole works without a global DOM', () => {
9696
</button>
9797
`)
9898
})
99+
100+
test('findBy works without a global DOM', async () => {
101+
const {window} = new JSDOM(`<div>
102+
<div data-testid="test-id" aria-label="test-label">test text content</div>
103+
<select><option>display value</option></select>
104+
<input placeholder="placeholder" />
105+
<img alt="test alt text" src="/lucy-ricardo.png" />
106+
<span title="test title" />
107+
<div role="dialog"></div>
108+
<div role="meter progressbar"></div>
109+
<header>header</header>
110+
<input type="hidden" />
111+
</div>`)
112+
113+
await expect(
114+
dtl.findByLabelText(window.document, 'test-label'),
115+
).resolves.toBeTruthy()
116+
await expect(
117+
dtl.findAllByLabelText(window.document, 'test-label'),
118+
).resolves.toHaveLength(1)
119+
await expect(
120+
dtl.findByPlaceholderText(window.document, 'placeholder'),
121+
).resolves.toBeTruthy()
122+
await expect(
123+
dtl.findAllByPlaceholderText(window.document, 'placeholder'),
124+
).resolves.toHaveLength(1)
125+
await expect(
126+
dtl.findByText(window.document, 'test text content'),
127+
).resolves.toBeTruthy()
128+
await expect(
129+
dtl.findAllByText(window.document, 'test text content'),
130+
).resolves.toHaveLength(1)
131+
await expect(
132+
dtl.findByAltText(window.document, 'test alt text'),
133+
).resolves.toBeTruthy()
134+
await expect(
135+
dtl.findAllByAltText(window.document, 'test alt text'),
136+
).resolves.toHaveLength(1)
137+
await expect(
138+
dtl.findByTitle(window.document, 'test title'),
139+
).resolves.toBeTruthy()
140+
await expect(
141+
dtl.findAllByTitle(window.document, 'test title'),
142+
).resolves.toHaveLength(1)
143+
await expect(
144+
dtl.findByDisplayValue(window.document, 'display value'),
145+
).resolves.toBeTruthy()
146+
await expect(
147+
dtl.findAllByDisplayValue(window.document, 'display value'),
148+
).resolves.toHaveLength(1)
149+
await expect(dtl.findByRole(window.document, 'dialog')).resolves.toBeTruthy()
150+
await expect(
151+
dtl.findAllByRole(window.document, 'dialog'),
152+
).resolves.toHaveLength(1)
153+
await expect(dtl.findByRole(window.document, 'meter')).resolves.toBeTruthy()
154+
await expect(
155+
dtl.findAllByRole(window.document, 'meter'),
156+
).resolves.toHaveLength(1)
157+
await expect(
158+
dtl.findByRole(window.document, 'progressbar', {queryFallbacks: true}),
159+
).resolves.toBeTruthy()
160+
await expect(
161+
dtl.findAllByRole(window.document, 'progressbar', {queryFallbacks: true}),
162+
).resolves.toHaveLength(1)
163+
await expect(dtl.findByRole(window.document, 'banner')).resolves.toBeTruthy()
164+
await expect(
165+
dtl.findAllByRole(window.document, 'banner'),
166+
).resolves.toHaveLength(1)
167+
await expect(
168+
dtl.findByTestId(window.document, 'test-id'),
169+
).resolves.toBeTruthy()
170+
await expect(
171+
dtl.findAllByTestId(window.document, 'test-id'),
172+
).resolves.toHaveLength(1)
173+
})

src/__tests__/text-matchers.js

+4
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@ cases(
231231
<input id="username" />`,
232232
queryFn: 'queryAllByLabelText',
233233
},
234+
queryAllByAriaLabelText: {
235+
dom: `<div aria-label="User ${LRM}name"/>`,
236+
queryFn: 'queryAllByLabelText',
237+
},
234238
queryAllByPlaceholderText: {
235239
dom: `<input placeholder="User ${LRM}name" />`,
236240
queryFn: 'queryAllByPlaceholderText',

src/__tests__/wait-for-element-to-be-removed.js

+14
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,20 @@ test('requires an element to exist first', () => {
4242
)
4343
})
4444

45+
test("requires element's parent to exist first", () => {
46+
const {getByTestId} = renderIntoDocument(`
47+
<div data-testid="div">asd</div>
48+
`)
49+
const div = getByTestId('div')
50+
div.parentElement.removeChild(div)
51+
52+
return expect(
53+
waitForElementToBeRemoved(div),
54+
).rejects.toThrowErrorMatchingInlineSnapshot(
55+
`"The element(s) given to waitForElementToBeRemoved are already removed. waitForElementToBeRemoved requires that the element(s) exist(s) before waiting for removal."`,
56+
)
57+
})
58+
4559
test('requires an unempty array of elements to exist first', () => {
4660
return expect(
4761
waitForElementToBeRemoved([]),

src/queries/label-text.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,12 @@ function queryAllByLabelText(
9191

9292
return labelledElements
9393
}, [])
94-
.concat(queryAllByAttribute('aria-label', container, text, {exact}))
94+
.concat(
95+
queryAllByAttribute('aria-label', container, text, {
96+
exact,
97+
normalizer: matchNormalizer,
98+
}),
99+
)
95100

96101
return Array.from(new Set(matchingLabelledElements)).filter(element =>
97102
element.matches(selector),

src/query-helpers.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,14 @@ function makeGetAllQuery(allQuery, getMissingError) {
9090
// this accepts a getter query function and returns a function which calls
9191
// waitFor and passing a function which invokes the getter.
9292
function makeFindQuery(getter) {
93-
return (container, text, options, waitForOptions) =>
94-
waitFor(() => {
95-
return getter(container, text, options)
96-
}, waitForOptions)
93+
return (container, text, options, waitForOptions) => {
94+
return waitFor(
95+
() => {
96+
return getter(container, text, options)
97+
},
98+
{container, ...waitForOptions},
99+
)
100+
}
97101
}
98102

99103
const wrapSingleQueryWithSuggestion = (query, queryAllByName, variant) => (

src/wait-for-element-to-be-removed.js

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ async function waitForElementToBeRemoved(callback, options) {
2020
const elements = Array.isArray(callback) ? callback : [callback]
2121
const getRemainingElements = elements.map(element => {
2222
let parent = element.parentElement
23+
if(parent === null) return () => null
2324
while (parent.parentElement) parent = parent.parentElement
2425
return () => (parent.contains(element) ? element : null)
2526
})

src/wait-for.js

+7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
setImmediate,
99
setTimeout,
1010
clearTimeout,
11+
checkContainerType,
1112
} from './helpers'
1213
import {getConfig, runWithExpensiveErrorDiagnosticsDisabled} from './config'
1314

@@ -89,6 +90,12 @@ function waitFor(
8990
await new Promise(r => setImmediate(r))
9091
}
9192
} else {
93+
try {
94+
checkContainerType(container)
95+
} catch (e) {
96+
reject(e)
97+
return
98+
}
9299
intervalId = setInterval(checkRealTimersCallback, interval)
93100
const {MutationObserver} = getWindowFromNode(container)
94101
observer = new MutationObserver(checkRealTimersCallback)

0 commit comments

Comments
 (0)