Skip to content

Commit 1eb9627

Browse files
authored
Merge branch 'main' into byrole_perf
2 parents 62785b8 + 4f965e9 commit 1eb9627

27 files changed

+497
-82
lines changed

.all-contributorsrc

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,14 @@
195195
]
196196
},
197197
{
198-
"login": "tdeschryver",
198+
"login": "timdeschryver",
199199
"name": "Tim Deschryver",
200-
"avatar_url": "https://avatars1.githubusercontent.com/u/28659384?v=4",
201-
"profile": "https://github.com/tdeschryver",
200+
"avatar_url": "https://avatars.githubusercontent.com/u/28659384?v=4",
201+
"profile": "http://timdeschryver.dev",
202202
"contributions": [
203203
"code",
204-
"test"
204+
"test",
205+
"review"
205206
]
206207
},
207208
{
@@ -637,7 +638,8 @@
637638
"code",
638639
"test",
639640
"doc",
640-
"infra"
641+
"infra",
642+
"review"
641643
]
642644
},
643645
{
@@ -1497,6 +1499,60 @@
14971499
"contributions": [
14981500
"bug"
14991501
]
1502+
},
1503+
{
1504+
"login": "robcaldecott",
1505+
"name": "Rob Caldecott",
1506+
"avatar_url": "https://avatars.githubusercontent.com/u/796702?v=4",
1507+
"profile": "https://github.com/robcaldecott",
1508+
"contributions": [
1509+
"bug"
1510+
]
1511+
},
1512+
{
1513+
"login": "Dennis273",
1514+
"name": "Dennis273",
1515+
"avatar_url": "https://avatars.githubusercontent.com/u/19815164?v=4",
1516+
"profile": "https://github.com/Dennis273",
1517+
"contributions": [
1518+
"code"
1519+
]
1520+
},
1521+
{
1522+
"login": "jacksonhardaker",
1523+
"name": "Jackson Hardaker",
1524+
"avatar_url": "https://avatars.githubusercontent.com/u/7596320?v=4",
1525+
"profile": "https://www.jacksonhardaker.dev",
1526+
"contributions": [
1527+
"test"
1528+
]
1529+
},
1530+
{
1531+
"login": "robin-drexler",
1532+
"name": "Robin Drexler",
1533+
"avatar_url": "https://avatars.githubusercontent.com/u/474248?v=4",
1534+
"profile": "https://www.robin-drexler.com/",
1535+
"contributions": [
1536+
"code"
1537+
]
1538+
},
1539+
{
1540+
"login": "dolevoper",
1541+
"name": "Omer Dolev",
1542+
"avatar_url": "https://avatars.githubusercontent.com/u/53278705?v=4",
1543+
"profile": "https://github.com/dolevoper",
1544+
"contributions": [
1545+
"code"
1546+
]
1547+
},
1548+
{
1549+
"login": "Lirlev48",
1550+
"name": "Lirlev48",
1551+
"avatar_url": "https://avatars.githubusercontent.com/u/58209233?v=4",
1552+
"profile": "https://github.com/Lirlev48",
1553+
"contributions": [
1554+
"code"
1555+
]
15001556
}
15011557
],
15021558
"repoHost": "https://github.com"

.codesandbox/ci.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"installCommand": "install:csb",
23
"sandboxes": ["github/kentcdodds/react-testing-library-examples"],
34
"node": "12"
45
}

.github/workflows/validate.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ name: validate
22
on:
33
push:
44
branches:
5-
- '+([0-9])?(.{+([0-9]),x}).x'
5+
# Match SemVer major release branches
6+
# e.g. "12.x" or "8.x"
7+
- '[0-9]+.x'
68
- 'main'
79
- 'next'
810
- 'next-major'
@@ -18,21 +20,20 @@ jobs:
1820
# Otherwise we would not know if the problem is tied to the Node.js version
1921
fail-fast: false
2022
matrix:
21-
# TODO: relax `'16.9.1'` to `16` once GitHub has 16.9.1 cached. 16.9.0 is broken due to https://github.com/nodejs/node/issues/40030
22-
node: [12, 14, '16.9.1']
23+
node: [12, 14, 16]
2324
runs-on: ubuntu-latest
2425
steps:
2526
- name: 🛑 Cancel Previous Runs
2627
uses: styfle/[email protected]
2728

2829
- name: ⬇️ Checkout repo
29-
uses: actions/checkout@v2
30+
uses: actions/checkout@v3
3031
with:
3132
# required by codecov/codecov-action
3233
fetch-depth: 0
3334

3435
- name: ⎔ Setup node
35-
uses: actions/setup-node@v2
36+
uses: actions/setup-node@v3
3637
with:
3738
node-version: ${{ matrix.node }}
3839

@@ -59,17 +60,16 @@ jobs:
5960
runs-on: ubuntu-latest
6061
if:
6162
${{ github.repository == 'testing-library/dom-testing-library' &&
62-
contains('refs/heads/main,refs/heads/beta,refs/heads/next,refs/heads/alpha',
63-
github.ref) && github.event_name == 'push' }}
63+
github.event_name == 'push' }}
6464
steps:
6565
- name: 🛑 Cancel Previous Runs
6666
uses: styfle/[email protected]
6767

6868
- name: ⬇️ Checkout repo
69-
uses: actions/checkout@v2
69+
uses: actions/checkout@v3
7070

7171
- name: ⎔ Setup node
72-
uses: actions/setup-node@v2
72+
uses: actions/setup-node@v3
7373
with:
7474
node-version: 14
7575

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ Thanks goes to these people ([emoji key][emojis]):
154154
<td align="center"><a href="https://github.com/alecook"><img src="https://avatars3.githubusercontent.com/u/725236?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Alex Cook</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=alecook" title="Documentation">📖</a> <a href="#example-alecook" title="Examples">💡</a> <a href="https://github.com/testing-library/dom-testing-library/pulls?q=is%3Apr+reviewed-by%3Aalecook" title="Reviewed Pull Requests">👀</a></td>
155155
<td align="center"><a href="https://github.com/dfcook"><img src="https://avatars3.githubusercontent.com/u/10348212?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Daniel Cook</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=dfcook" title="Code">💻</a> <a href="https://github.com/testing-library/dom-testing-library/commits?author=dfcook" title="Documentation">📖</a> <a href="https://github.com/testing-library/dom-testing-library/commits?author=dfcook" title="Tests">⚠️</a></td>
156156
<td align="center"><a href="https://github.com/thchia"><img src="https://avatars2.githubusercontent.com/u/21194045?s=400&v=4?s=100" width="100px;" alt=""/><br /><sub><b>Thomas Chia</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/issues?q=author%3Athchia" title="Bug reports">🐛</a> <a href="https://github.com/testing-library/dom-testing-library/commits?author=thchia" title="Code">💻</a></td>
157-
<td align="center"><a href="https://github.com/tdeschryver"><img src="https://avatars1.githubusercontent.com/u/28659384?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Tim Deschryver</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=tdeschryver" title="Code">💻</a> <a href="https://github.com/testing-library/dom-testing-library/commits?author=tdeschryver" title="Tests">⚠️</a></td>
157+
<td align="center"><a href="http://timdeschryver.dev"><img src="https://avatars.githubusercontent.com/u/28659384?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Tim Deschryver</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=timdeschryver" title="Code">💻</a> <a href="https://github.com/testing-library/dom-testing-library/commits?author=timdeschryver" title="Tests">⚠️</a> <a href="https://github.com/testing-library/dom-testing-library/pulls?q=is%3Apr+reviewed-by%3Atimdeschryver" title="Reviewed Pull Requests">👀</a></td>
158158
<td align="center"><a href="https://alexkrolick.com"><img src="https://avatars3.githubusercontent.com/u/1571667?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Alex Krolick</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=alexkrolick" title="Code">💻</a></td>
159159
<td align="center"><a href="http://www.maddijoyce.com"><img src="https://avatars2.githubusercontent.com/u/2224291?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Maddi Joyce</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=maddijoyce" title="Code">💻</a></td>
160160
</tr>
@@ -213,7 +213,7 @@ Thanks goes to these people ([emoji key][emojis]):
213213
<td align="center"><a href="https://github.com/michaellasky"><img src="https://avatars2.githubusercontent.com/u/6646599?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Michael Lasky</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=michaellasky" title="Code">💻</a> <a href="https://github.com/testing-library/dom-testing-library/commits?author=michaellasky" title="Tests">⚠️</a> <a href="https://github.com/testing-library/dom-testing-library/commits?author=michaellasky" title="Documentation">📖</a></td>
214214
</tr>
215215
<tr>
216-
<td align="center"><a href="https://twitter.com/sebsilbermann"><img src="https://avatars3.githubusercontent.com/u/12292047?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Sebastian Silbermann</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=eps1lon" title="Code">💻</a> <a href="https://github.com/testing-library/dom-testing-library/commits?author=eps1lon" title="Tests">⚠️</a> <a href="https://github.com/testing-library/dom-testing-library/commits?author=eps1lon" title="Documentation">📖</a> <a href="#infra-eps1lon" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
216+
<td align="center"><a href="https://twitter.com/sebsilbermann"><img src="https://avatars3.githubusercontent.com/u/12292047?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Sebastian Silbermann</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=eps1lon" title="Code">💻</a> <a href="https://github.com/testing-library/dom-testing-library/commits?author=eps1lon" title="Tests">⚠️</a> <a href="https://github.com/testing-library/dom-testing-library/commits?author=eps1lon" title="Documentation">📖</a> <a href="#infra-eps1lon" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/testing-library/dom-testing-library/pulls?q=is%3Apr+reviewed-by%3Aeps1lon" title="Reviewed Pull Requests">👀</a></td>
217217
<td align="center"><a href="https://dylanvann.com/"><img src="https://avatars0.githubusercontent.com/u/1537615?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Dylan Vann</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=DylanVann" title="Code">💻</a></td>
218218
<td align="center"><a href="https://afontcu.dev"><img src="https://avatars0.githubusercontent.com/u/9197791?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Adrià Fontcuberta</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=afontcu" title="Code">💻</a> <a href="https://github.com/testing-library/dom-testing-library/commits?author=afontcu" title="Tests">⚠️</a> <a href="https://github.com/testing-library/dom-testing-library/commits?author=afontcu" title="Documentation">📖</a></td>
219219
<td align="center"><a href="http://thomlom.dev"><img src="https://avatars3.githubusercontent.com/u/16003285?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Thomas Lombart</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=thomlom" title="Code">💻</a></td>
@@ -327,6 +327,14 @@ Thanks goes to these people ([emoji key][emojis]):
327327
<td align="center"><a href="https://github.com/IanVS"><img src="https://avatars.githubusercontent.com/u/4616705?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ian VanSchooten</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=IanVS" title="Code">💻</a></td>
328328
<td align="center"><a href="http://supervanya.com"><img src="https://avatars.githubusercontent.com/u/12336038?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Vanya Prokopovich</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/issues?q=author%3Asupervanya" title="Bug reports">🐛</a></td>
329329
<td align="center"><a href="https://github.com/jrnail23"><img src="https://avatars.githubusercontent.com/u/392612?v=4?s=100" width="100px;" alt=""/><br /><sub><b>James Nail</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/issues?q=author%3Ajrnail23" title="Bug reports">🐛</a></td>
330+
<td align="center"><a href="https://github.com/robcaldecott"><img src="https://avatars.githubusercontent.com/u/796702?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Rob Caldecott</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/issues?q=author%3Arobcaldecott" title="Bug reports">🐛</a></td>
331+
</tr>
332+
<tr>
333+
<td align="center"><a href="https://github.com/Dennis273"><img src="https://avatars.githubusercontent.com/u/19815164?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Dennis273</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=Dennis273" title="Code">💻</a></td>
334+
<td align="center"><a href="https://www.jacksonhardaker.dev"><img src="https://avatars.githubusercontent.com/u/7596320?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jackson Hardaker</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=jacksonhardaker" title="Tests">⚠️</a></td>
335+
<td align="center"><a href="https://www.robin-drexler.com/"><img src="https://avatars.githubusercontent.com/u/474248?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Robin Drexler</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=robin-drexler" title="Code">💻</a></td>
336+
<td align="center"><a href="https://github.com/dolevoper"><img src="https://avatars.githubusercontent.com/u/53278705?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Omer Dolev</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=dolevoper" title="Code">💻</a></td>
337+
<td align="center"><a href="https://github.com/Lirlev48"><img src="https://avatars.githubusercontent.com/u/58209233?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Lirlev48</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=Lirlev48" title="Code">💻</a></td>
330338
</tr>
331339
</table>
332340

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"scripts": {
2727
"build": "kcd-scripts build --no-ts-defs --ignore \"**/__tests__/**,**/__node_tests__/**,**/__mocks__/**\" && kcd-scripts build --no-ts-defs --bundle --no-clean",
2828
"format": "kcd-scripts format",
29+
"install:csb": "npm install",
2930
"lint": "kcd-scripts lint",
3031
"setup": "npm install && npm run validate -s",
3132
"test": "kcd-scripts test",

src/__tests__/element-queries.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ test('get throws a useful error message', () => {
5757
<div />
5858
</div>
5959
`)
60+
expect(() => getByText('Lucy Ricardo'))
61+
.toThrowErrorMatchingInlineSnapshot(`
62+
Unable to find an element with the text: Lucy Ricardo (normalized from 'Lucy Ricardo'). This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.
63+
64+
Ignored nodes: comments, <script />, <style />
65+
<div>
66+
<div />
67+
</div>
68+
`)
6069
expect(() => getByTestId('LucyRicardo')).toThrowErrorMatchingInlineSnapshot(`
6170
Unable to find an element by: [data-testid="LucyRicardo"]
6271
@@ -1071,6 +1080,18 @@ test('getByText ignores script tags by default', () => {
10711080
expect(getAllByText(/hello/i, {ignore: false})).toHaveLength(3)
10721081
})
10731082

1083+
test('the default value for `ignore` can be configured', () => {
1084+
configure({defaultIgnore: 'style'})
1085+
1086+
const {getAllByText} = render(
1087+
'<script>Hello</script><div>Hello</div><style>.Hello{}</style>',
1088+
)
1089+
const noStyle = getAllByText(/hello/i)
1090+
expect(noStyle).toHaveLength(2)
1091+
expect(noStyle[0].tagName).toBe('SCRIPT')
1092+
expect(noStyle[1].tagName).toBe('DIV')
1093+
})
1094+
10741095
test('get/query input element by current value', () => {
10751096
const {getByDisplayValue, queryByDisplayValue, getByTestId} =
10761097
renderIntoDocument(`

src/__tests__/events.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@ const eventTypes = [
7171
events: ['scroll'],
7272
elementType: 'div',
7373
},
74+
{
75+
type: '',
76+
events: ['load', 'error'],
77+
elementType: 'img',
78+
},
79+
{
80+
type: '',
81+
events: ['load', 'error'],
82+
elementType: 'script',
83+
},
7484
{
7585
type: 'Wheel',
7686
events: ['wheel'],
@@ -105,11 +115,6 @@ const eventTypes = [
105115
],
106116
elementType: 'video',
107117
},
108-
{
109-
type: 'Image',
110-
events: ['load', 'error'],
111-
elementType: 'img',
112-
},
113118
{
114119
type: 'Animation',
115120
events: ['animationStart', 'animationEnd', 'animationIteration'],
@@ -172,17 +177,17 @@ eventTypes.forEach(({type, events, elementType}) => {
172177
expect(spy).toHaveBeenCalledTimes(1)
173178
})
174179
})
175-
176-
it('fires resize', () => {
177-
const node = document.defaultView
178-
const spy = jest.fn()
179-
node.addEventListener('resize', spy, {once: true})
180-
fireEvent.resize(node)
181-
expect(spy).toHaveBeenCalledTimes(1)
182-
})
183180
})
184181
})
185182

183+
it('fires resize', () => {
184+
const node = document.defaultView
185+
const spy = jest.fn()
186+
node.addEventListener('resize', spy, {once: true})
187+
fireEvent.resize(node)
188+
expect(spy).toHaveBeenCalledTimes(1)
189+
})
190+
186191
describe(`Bubbling Events`, () => {
187192
bubblingEvents.forEach(event =>
188193
it(`bubbles ${event}`, () => {

src/__tests__/helpers.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,22 @@ describe('window retrieval throws when given something other than a node', () =>
2525
`It looks like you passed an Array instead of a DOM node. Did you do something like \`fireEvent.click(screen.getAllBy...\` when you meant to use a \`getBy\` query \`fireEvent.click(screen.getBy...\`?`,
2626
)
2727
})
28+
test('window is not available for node', () => {
29+
const elem = document.createElement('div')
30+
Object.defineProperty(elem.ownerDocument, 'defaultView', {
31+
get: function get() {
32+
return null
33+
},
34+
})
35+
36+
expect(() => getWindowFromNode(elem)).toThrowErrorMatchingInlineSnapshot(
37+
`It looks like the window object is not available for the provided node.`,
38+
)
39+
})
40+
2841
test('unknown as node', () => {
2942
expect(() => getWindowFromNode({})).toThrowErrorMatchingInlineSnapshot(
30-
`Unable to find the "window" object for the given node. Please file an issue with the code that's causing you to see this error: https://github.com/testing-library/dom-testing-library/issues/new`,
43+
`The given node is not an Element, the node type is: object.`,
3144
)
3245
})
3346
})

src/__tests__/matches.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@ test('matchers accept regex', () => {
1515
expect(fuzzyMatches('ABC', node, /ABC/, normalizer)).toBe(true)
1616
})
1717

18+
// https://stackoverflow.com/questions/1520800/why-does-a-regexp-with-global-flag-give-wrong-results
19+
test('a regex with the global flag consistently (re-)finds a match', () => {
20+
const regex = /ABC/g
21+
const spy = jest.spyOn(console, 'warn').mockImplementation()
22+
23+
expect(matches('ABC', node, regex, normalizer)).toBe(true)
24+
expect(fuzzyMatches('ABC', node, regex, normalizer)).toBe(true)
25+
26+
expect(spy).toBeCalledTimes(2)
27+
expect(spy).toHaveBeenCalledWith(
28+
`To match all elements we had to reset the lastIndex of the RegExp because the global flag is enabled. We encourage to remove the global flag from the RegExp.`,
29+
)
30+
31+
console.warn.mockClear()
32+
})
33+
1834
test('matchers accept functions', () => {
1935
expect(matches('ABC', node, text => text === 'ABC', normalizer)).toBe(true)
2036
expect(fuzzyMatches('ABC', node, text => text === 'ABC', normalizer)).toBe(

0 commit comments

Comments
 (0)