Skip to content

Commit 3a575ad

Browse files
committed
feat: bump to dom-testing-library v3
BREAKING CHANGE: now using v3 of dom-testing-library
1 parent 2889df5 commit 3a575ad

File tree

6 files changed

+54
-12
lines changed

6 files changed

+54
-12
lines changed

lib/index.ts

+16
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,22 @@ export function getQueriesForElement<T>(
157157
o.queryAllByTitle = createDelegateFor('queryAllByTitle', contextFn)
158158
o.getByTitle = createDelegateFor('getByTitle', contextFn)
159159
o.getAllByTitle = createDelegateFor('getAllByTitle', contextFn)
160+
161+
o.queryByRole = createDelegateFor('queryByRole', contextFn)
162+
o.queryAllByRole = createDelegateFor('queryAllByRole', contextFn)
163+
o.getByRole = createDelegateFor('getByRole', contextFn)
164+
o.getAllByRole = createDelegateFor('getAllByRole', contextFn)
165+
166+
o.queryBySelectText = createDelegateFor('queryBySelectText', contextFn)
167+
o.queryAllBySelectText = createDelegateFor('queryAllBySelectText', contextFn)
168+
o.getBySelectText = createDelegateFor('getBySelectText', contextFn)
169+
o.getAllBySelectText = createDelegateFor('getAllBySelectText', contextFn)
170+
171+
o.queryByValue = createDelegateFor('queryByValue', contextFn)
172+
o.queryAllByValue = createDelegateFor('queryAllByValue', contextFn)
173+
o.getByValue = createDelegateFor('getByValue', contextFn)
174+
o.getAllByValue = createDelegateFor('getAllByValue', contextFn)
175+
160176
o.getNodeText = createDelegateFor<string>('getNodeText', contextFn, processNodeText)
161177

162178
return o

lib/typedefs.ts

+15
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,21 @@ interface IQueryMethods {
3333
queryAllByTitle(el: Element, m: Matcher, opts?: MatcherOptions): Promise<Element[]>
3434
getByTitle(el: Element, m: Matcher, opts?: MatcherOptions): Promise<Element>
3535
getAllByTitle(el: Element, m: Matcher, opts?: MatcherOptions): Promise<Element[]>
36+
37+
queryByRole(el: Element, m: Matcher, opts?: MatcherOptions): Promise<Element | null>
38+
queryAllByRole(el: Element, m: Matcher, opts?: MatcherOptions): Promise<Element[]>
39+
getByRole(el: Element, m: Matcher, opts?: MatcherOptions): Promise<Element>
40+
getAllByRole(el: Element, m: Matcher, opts?: MatcherOptions): Promise<Element[]>
41+
42+
queryBySelectText(el: Element, m: Matcher, opts?: MatcherOptions): Promise<Element | null>
43+
queryAllBySelectText(el: Element, m: Matcher, opts?: MatcherOptions): Promise<Element[]>
44+
getBySelectText(el: Element, m: Matcher, opts?: MatcherOptions): Promise<Element>
45+
getAllBySelectText(el: Element, m: Matcher, opts?: MatcherOptions): Promise<Element[]>
46+
47+
queryByValue(el: Element, m: Matcher, opts?: MatcherOptions): Promise<Element | null>
48+
queryAllByValue(el: Element, m: Matcher, opts?: MatcherOptions): Promise<Element[]>
49+
getByValue(el: Element, m: Matcher, opts?: MatcherOptions): Promise<Element>
50+
getAllByValue(el: Element, m: Matcher, opts?: MatcherOptions): Promise<Element[]>
3651
}
3752

3853
type IScopedQueryMethods = {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
}
4343
},
4444
"dependencies": {
45-
"dom-testing-library": "^2.6.1",
45+
"dom-testing-library": "^3.11.0",
4646
"wait-for-expect": "^0.4.0"
4747
},
4848
"devDependencies": {

test/__snapshots__/extend.test.ts.snap

+11-11
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ exports[`lib/extend.ts should handle the LabelText methods 1`] = `"<input id=\\"
55
exports[`lib/extend.ts should handle the get* method failures 1`] = `
66
"Evaluation failed: Error: Unable to find an element with the title: missing.
77
8-
[36m<div[39m
9-
[33mid[39m=[32m\\"scoped\\"[39m
10-
[36m>[39m
11-
[0m
12-
[0m
13-
[36m<h3>[39m
14-
[0mHello h3[0m
15-
[36m</h3>[39m
16-
[0m
17-
[0m
18-
[36m</div>[39m
8+
<div
9+
id=\\"scoped\\"
10+
>
11+
12+
13+
<h3>
14+
Hello h3
15+
</h3>
16+
17+
18+
</div>
1919
at getElementError <stack>:X:X)
2020
at getAllByTitle <stack>:X:X)
2121
at firstResultOrNull <stack>:X:X)

test/extend.test.ts

+7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ describe('lib/extend.ts', () => {
2525
expect(await page.evaluate(el => el.textContent, element)).toEqual('Hello h1')
2626
})
2727

28+
it('should use the new v3 methods', async () => {
29+
const element = await document.queryByRole('presentation')
30+
expect(element).toBeTruthy()
31+
/* istanbul ignore next */
32+
expect(await page.evaluate(el => el.textContent, element)).toContain('Layout table')
33+
})
34+
2835
it('should handle regex matching', async () => {
2936
const element = await document.queryByText(/HeLlO/i)
3037
expect(element).toBeTruthy()

test/fixtures/page.html

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ <h2>Hello h2</h2>
1212
<div id="scoped">
1313
<h3>Hello h3</h3>
1414
</div>
15+
16+
<table role="presentation">
17+
<td>Layout table</td>
18+
</table>
1519
</body>
1620

1721
</html>

0 commit comments

Comments
 (0)