Skip to content

Commit 45ffcb4

Browse files
authored
Merge branch 'master' into patch-1
2 parents 4b41f2f + 32dd725 commit 45ffcb4

33 files changed

+1056
-77
lines changed

.all-contributorsrc

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,79 @@
944944
"contributions": [
945945
"doc"
946946
]
947+
},
948+
{
949+
"login": "Lukas-Kullmann",
950+
"name": "Lukas",
951+
"avatar_url": "https://avatars0.githubusercontent.com/u/387547?v=4",
952+
"profile": "https://github.com/Lukas-Kullmann",
953+
"contributions": [
954+
"code",
955+
"test"
956+
]
957+
},
958+
{
959+
"login": "pelotom",
960+
"name": "Tom Crockett",
961+
"avatar_url": "https://avatars2.githubusercontent.com/u/128019?v=4",
962+
"profile": "https://twitter.com/pelotom",
963+
"contributions": [
964+
"code",
965+
"test"
966+
]
967+
},
968+
{
969+
"login": "appleJax",
970+
"name": "Kevin Brewer",
971+
"avatar_url": "https://avatars1.githubusercontent.com/u/13618860?v=4",
972+
"profile": "https://github.com/appleJax",
973+
"contributions": [
974+
"code",
975+
"test"
976+
]
977+
},
978+
{
979+
"login": "benmonro",
980+
"name": "Ben Monro",
981+
"avatar_url": "https://avatars3.githubusercontent.com/u/399236?v=4",
982+
"profile": "https://github.com/benmonro",
983+
"contributions": [
984+
"code",
985+
"ideas",
986+
"test",
987+
"doc"
988+
]
989+
},
990+
{
991+
"login": "smeijer",
992+
"name": "Stephan Meijer",
993+
"avatar_url": "https://avatars1.githubusercontent.com/u/1196524?v=4",
994+
"profile": "https://github.com/smeijer",
995+
"contributions": [
996+
"ideas",
997+
"code",
998+
"test"
999+
]
1000+
},
1001+
{
1002+
"login": "Jnforja",
1003+
"name": "João Forja",
1004+
"avatar_url": "https://avatars2.githubusercontent.com/u/7002157?v=4",
1005+
"profile": "https://joaoforja.com/",
1006+
"contributions": [
1007+
"code",
1008+
"test"
1009+
]
1010+
},
1011+
{
1012+
"login": "nickmccurdy",
1013+
"name": "Nick McCurdy",
1014+
"avatar_url": "https://avatars0.githubusercontent.com/u/927220?v=4",
1015+
"profile": "https://nickmccurdy.com/",
1016+
"contributions": [
1017+
"doc",
1018+
"code"
1019+
]
9471020
}
9481021
],
9491022
"repoHost": "https://github.com"

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ merge of your pull request!
3636

3737
- [ ] Documentation added to the
3838
[docs site](https://github.com/testing-library/testing-library-docs)
39-
- [ ] I've prepared a PR for types targeting
40-
[DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/testing-library__dom)
4139
- [ ] Tests
40+
- [ ] Typescript definitions updated
4241
- [ ] Ready to be merged
4342
<!-- In your opinion, is this ready to be merged as soon as it's reviewed? -->
4443

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,15 @@ Thanks goes to these people ([emoji key][emojis]):
254254
<td align="center"><a href="https://github.com/mzdunek93"><img src="https://avatars0.githubusercontent.com/u/10826511?v=4" width="100px;" alt=""/><br /><sub><b>Michał Zdunek</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=mzdunek93" title="Code">💻</a></td>
255255
<td align="center"><a href="https://github.com/Lagily"><img src="https://avatars2.githubusercontent.com/u/42535205?v=4" width="100px;" alt=""/><br /><sub><b>Ali Nasserzadeh</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=Lagily" title="Code">💻</a></td>
256256
<td align="center"><a href="https://darekkay.com"><img src="https://avatars0.githubusercontent.com/u/3101914?v=4" width="100px;" alt=""/><br /><sub><b>Darek Kay</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=darekkay" title="Documentation">📖</a></td>
257+
<td align="center"><a href="https://github.com/Lukas-Kullmann"><img src="https://avatars0.githubusercontent.com/u/387547?v=4" width="100px;" alt=""/><br /><sub><b>Lukas</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=Lukas-Kullmann" title="Code">💻</a> <a href="https://github.com/testing-library/dom-testing-library/commits?author=Lukas-Kullmann" title="Tests">⚠️</a></td>
258+
<td align="center"><a href="https://twitter.com/pelotom"><img src="https://avatars2.githubusercontent.com/u/128019?v=4" width="100px;" alt=""/><br /><sub><b>Tom Crockett</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=pelotom" title="Code">💻</a> <a href="https://github.com/testing-library/dom-testing-library/commits?author=pelotom" title="Tests">⚠️</a></td>
259+
</tr>
260+
<tr>
261+
<td align="center"><a href="https://github.com/appleJax"><img src="https://avatars1.githubusercontent.com/u/13618860?v=4" width="100px;" alt=""/><br /><sub><b>Kevin Brewer</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=appleJax" title="Code">💻</a> <a href="https://github.com/testing-library/dom-testing-library/commits?author=appleJax" title="Tests">⚠️</a></td>
262+
<td align="center"><a href="https://github.com/benmonro"><img src="https://avatars3.githubusercontent.com/u/399236?v=4" width="100px;" alt=""/><br /><sub><b>Ben Monro</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=benmonro" title="Code">💻</a> <a href="#ideas-benmonro" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/testing-library/dom-testing-library/commits?author=benmonro" title="Tests">⚠️</a> <a href="https://github.com/testing-library/dom-testing-library/commits?author=benmonro" title="Documentation">📖</a></td>
263+
<td align="center"><a href="https://github.com/smeijer"><img src="https://avatars1.githubusercontent.com/u/1196524?v=4" width="100px;" alt=""/><br /><sub><b>Stephan Meijer</b></sub></a><br /><a href="#ideas-smeijer" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/testing-library/dom-testing-library/commits?author=smeijer" title="Code">💻</a> <a href="https://github.com/testing-library/dom-testing-library/commits?author=smeijer" title="Tests">⚠️</a></td>
264+
<td align="center"><a href="https://joaoforja.com/"><img src="https://avatars2.githubusercontent.com/u/7002157?v=4" width="100px;" alt=""/><br /><sub><b>João Forja</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=Jnforja" title="Code">💻</a> <a href="https://github.com/testing-library/dom-testing-library/commits?author=Jnforja" title="Tests">⚠️</a></td>
265+
<td align="center"><a href="https://nickmccurdy.com/"><img src="https://avatars0.githubusercontent.com/u/927220?v=4" width="100px;" alt=""/><br /><sub><b>Nick McCurdy</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=nickmccurdy" title="Documentation">📖</a> <a href="https://github.com/testing-library/dom-testing-library/commits?author=nickmccurdy" title="Code">💻</a></td>
257266
</tr>
258267
</table>
259268

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,20 @@
3838
"types"
3939
],
4040
"dependencies": {
41-
"@babel/runtime": "^7.9.6",
41+
"@babel/runtime": "^7.10.2",
4242
"aria-query": "^4.0.2",
43-
"dom-accessibility-api": "^0.4.4",
43+
"dom-accessibility-api": "^0.4.5",
4444
"pretty-format": "^25.5.0"
4545
},
4646
"devDependencies": {
47-
"dtslint": "^3.4.2",
48-
"@testing-library/jest-dom": "^5.5.0",
47+
"@testing-library/jest-dom": "^5.9.0",
48+
"dtslint": "^3.6.9",
4949
"jest-in-case": "^1.0.2",
5050
"jest-serializer-ansi": "^1.0.3",
5151
"jest-watch-select-projects": "^2.0.0",
5252
"jsdom": "^16.2.2",
53-
"kcd-scripts": "^6.0.0"
53+
"kcd-scripts": "^6.2.0",
54+
"typescript": "^3.9.5"
5455
},
5556
"eslintConfig": {
5657
"extends": "./node_modules/kcd-scripts/eslint.js",
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
import {
2+
getByLabelText,
3+
getAllByLabelText,
4+
queryAllByLabelText,
5+
queryByLabelText,
6+
findByLabelText,
7+
findAllByLabelText,
8+
getByPlaceholderText,
9+
getAllByPlaceholderText,
10+
queryAllByPlaceholderText,
11+
queryByPlaceholderText,
12+
findByPlaceholderText,
13+
findAllByPlaceholderText,
14+
getByText,
15+
getAllByText,
16+
queryAllByText,
17+
queryByText,
18+
findByText,
19+
findAllByText,
20+
getByAltText,
21+
getAllByAltText,
22+
queryAllByAltText,
23+
queryByAltText,
24+
findByAltText,
25+
findAllByAltText,
26+
getByTitle,
27+
getAllByTitle,
28+
queryAllByTitle,
29+
queryByTitle,
30+
findByTitle,
31+
findAllByTitle,
32+
getByDisplayValue,
33+
getAllByDisplayValue,
34+
queryAllByDisplayValue,
35+
queryByDisplayValue,
36+
findByDisplayValue,
37+
findAllByDisplayValue,
38+
getByRole,
39+
getAllByRole,
40+
queryAllByRole,
41+
queryByRole,
42+
findByRole,
43+
findAllByRole,
44+
getByTestId,
45+
getAllByTestId,
46+
queryAllByTestId,
47+
queryByTestId,
48+
findByTestId,
49+
findAllByTestId,
50+
} from '..'
51+
52+
describe('synchronous queries throw on invalid container type', () => {
53+
test.each([
54+
['getByLabelText', getByLabelText],
55+
['getAllByLabelText', getAllByLabelText],
56+
['queryByLabelText', queryByLabelText],
57+
['queryAllByLabelText', queryAllByLabelText],
58+
['getByPlaceholderText', getByPlaceholderText],
59+
['getAllByPlaceholderText', getAllByPlaceholderText],
60+
['queryByPlaceholderText', queryByPlaceholderText],
61+
['queryAllByPlaceholderText', queryAllByPlaceholderText],
62+
['getByText', getByText],
63+
['getAllByText', getAllByText],
64+
['queryByText', queryByText],
65+
['queryAllByText', queryAllByText],
66+
['getByAltText', getByAltText],
67+
['getAllByAltText', getAllByAltText],
68+
['queryByAltText', queryByAltText],
69+
['queryAllByAltText', queryAllByAltText],
70+
['getByTitle', getByTitle],
71+
['getAllByTitle', getAllByTitle],
72+
['queryByTitle', queryByTitle],
73+
['queryAllByTitle', queryAllByTitle],
74+
['getByDisplayValue', getByDisplayValue],
75+
['getAllByDisplayValue', getAllByDisplayValue],
76+
['queryByDisplayValue', queryByDisplayValue],
77+
['queryAllByDisplayValue', queryAllByDisplayValue],
78+
['getByRole', getByRole],
79+
['getAllByRole', getAllByRole],
80+
['queryByRole', queryByRole],
81+
['queryAllByRole', queryAllByRole],
82+
['getByTestId', getByTestId],
83+
['getAllByTestId', getAllByTestId],
84+
['queryByTestId', queryByTestId],
85+
['queryAllByTestId', queryAllByTestId],
86+
])('%s', (_queryName, query) => {
87+
expect(() =>
88+
query('invalid type for container', 'irrelevant text'),
89+
).toThrowErrorMatchingInlineSnapshot(
90+
`"Expected container to be an Element, a Document or a DocumentFragment but got string."`,
91+
)
92+
})
93+
})
94+
95+
describe('asynchronous queries throw on invalid container type', () => {
96+
test.each([
97+
['findByLabelText', findByLabelText],
98+
['findAllByLabelText', findAllByLabelText],
99+
['findByPlaceholderText', findByPlaceholderText],
100+
['findAllByPlaceholderText', findAllByPlaceholderText],
101+
['findByText', findByText],
102+
['findAllByText', findAllByText],
103+
['findByAltText', findByAltText],
104+
['findAllByAltText', findAllByAltText],
105+
['findByTitle', findByTitle],
106+
['findAllByTitle', findAllByTitle],
107+
['findByDisplayValue', findByDisplayValue],
108+
['findAllByDisplayValue', findAllByDisplayValue],
109+
['findByRole', findByRole],
110+
['findAllByRole', findAllByRole],
111+
['findByTestId', findByTestId],
112+
['findAllByTestId', findAllByTestId],
113+
])('%s', (_queryName, query) => {
114+
const queryOptions = {}
115+
const waitOptions = {timeout: 1}
116+
return expect(
117+
query(
118+
'invalid type for container',
119+
'irrelevant text',
120+
queryOptions,
121+
waitOptions,
122+
),
123+
).rejects.toThrowErrorMatchingInlineSnapshot(
124+
`"Expected container to be an Element, a Document or a DocumentFragment but got string."`,
125+
)
126+
})
127+
})

src/__tests__/event-wrapper.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import {configure, fireEvent} from '..'
2+
3+
let originalConfig
4+
5+
beforeEach(() => {
6+
configure(oldConfig => {
7+
originalConfig = oldConfig
8+
return null
9+
})
10+
})
11+
12+
afterEach(() => {
13+
jest.clearAllMocks()
14+
configure(originalConfig)
15+
})
16+
17+
test('fireEvent calls the eventWrapper', () => {
18+
const mockEventWrapper = jest.fn()
19+
configure(() => {
20+
return {eventWrapper: mockEventWrapper}
21+
})
22+
const el = document.createElement('div')
23+
fireEvent.click(el)
24+
expect(mockEventWrapper).toHaveBeenCalledWith(expect.any(Function))
25+
expect(mockEventWrapper).toHaveBeenCalledTimes(1)
26+
})
27+
28+
test('fireEvent has a default eventWrapper', () => {
29+
const el = document.createElement('div')
30+
expect(() => fireEvent.click(el)).not.toThrow()
31+
})

src/__tests__/helpers.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
1-
import {getDocument} from '../helpers'
1+
import {getDocument, checkContainerType} from '../helpers'
22

33
test('returns global document if exists', () => {
44
expect(getDocument()).toBe(document)
55
})
6+
7+
describe('query container validation throws when validation fails', () => {
8+
test('undefined as container', () => {
9+
expect(() =>
10+
checkContainerType(undefined),
11+
).toThrowErrorMatchingInlineSnapshot(
12+
`"Expected container to be an Element, a Document or a DocumentFragment but got undefined."`,
13+
)
14+
})
15+
test('null as container', () => {
16+
expect(() => checkContainerType(null)).toThrowErrorMatchingInlineSnapshot(
17+
`"Expected container to be an Element, a Document or a DocumentFragment but got null."`,
18+
)
19+
})
20+
test('array as container', () => {
21+
expect(() => checkContainerType([])).toThrowErrorMatchingInlineSnapshot(
22+
`"Expected container to be an Element, a Document or a DocumentFragment but got Array."`,
23+
)
24+
})
25+
test('object as container', () => {
26+
expect(() => checkContainerType({})).toThrowErrorMatchingInlineSnapshot(
27+
`"Expected container to be an Element, a Document or a DocumentFragment but got Object."`,
28+
)
29+
})
30+
})

src/__tests__/role.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,12 @@ Here are the accessible roles:
343343
`)
344344
})
345345

346+
test('has no useful error message in findBy', async () => {
347+
const {findByRole} = render(`<li />`)
348+
349+
await expect(findByRole('option', {timeout: 1})).rejects.toThrow('Unable to find role="option"')
350+
})
351+
346352
test('explicit role is most specific', () => {
347353
const {getByRole} = renderIntoDocument(
348354
`<button role="tab" aria-label="my-tab" />`,

0 commit comments

Comments
 (0)