Skip to content

Commit 539a4e2

Browse files
feat: support additional configure options
Include the following config options in the exported Config type: - asyncUtilTimeout - computedStyleSupportsPseudoElements - defaultHidden - throwSuggestions Add tests for each new option.
1 parent d10d8b4 commit 539a4e2

File tree

3 files changed

+68
-8
lines changed

3 files changed

+68
-8
lines changed

src/types.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ import {
55
} from '@testing-library/dom'
66
import {Element} from 'webdriverio'
77

8-
export type Config = Pick<BaseConfig, 'testIdAttribute'>
8+
export type Config = Pick<
9+
BaseConfig,
10+
| 'testIdAttribute'
11+
| 'asyncUtilTimeout'
12+
| 'computedStyleSupportsPseudoElements'
13+
| 'defaultHidden'
14+
| 'throwSuggestions'
15+
>
916

1017
export type WebdriverIOQueryReturnType<T> = T extends Promise<HTMLElement>
1118
? Element

test-app/index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
section {
1717
padding: 10px;
1818
}
19+
20+
.pseudo-name::after {
21+
content: 'Named by pseudo element';
22+
}
1923
</style>
2024
</head>
2125

@@ -81,6 +85,16 @@ <h2>configure</h2>
8185
src="data:image/png;base64,"
8286
onclick="this.style.border = '5px solid red'"
8387
/>
88+
<button class="pseudo-name" />
89+
<section aria-hidden="true" style="visibility: hidden;">
90+
<button>
91+
Hidden button
92+
</button>
93+
</section>
94+
<button
95+
data-testid="button-that-should-not-use-testid"
96+
aria-label="Can be targeted by other queries"
97+
/>
8498
</section>
8599
<section>
86100
<h2>configure standalone</h2>

test/configure.e2e.ts

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,64 @@
1-
import {setupBrowser, configure} from '../src';
1+
import {setupBrowser, configure} from '../src'
22

33
describe('configure', () => {
4-
beforeEach(() => {
5-
configure({testIdAttribute: 'data-automation-id'})
6-
})
74
afterEach(() => {
85
configure({})
96
})
107

11-
it('supports alternative testIdAttribute', async () => {
8+
it('supports setting testIdAttribute', async () => {
9+
configure({testIdAttribute: 'data-automation-id'})
10+
1211
const {getByTestId} = setupBrowser(browser)
1312

1413
expect(await getByTestId('image-with-random-alt-tag')).toBeDefined()
1514
})
1615

16+
it('supports setting asyncUtilTimeout', async () => {
17+
configure({asyncUtilTimeout: 0})
18+
19+
const {findByText} = setupBrowser(browser)
20+
21+
await expect(() =>
22+
findByText('Unique Delayed Button Text'),
23+
).rejects.toThrowError()
24+
})
25+
26+
it('supports setting computedStyleSupportsPseudoElements', async () => {
27+
configure({computedStyleSupportsPseudoElements: true})
28+
29+
const {getByRole} = setupBrowser(browser)
30+
31+
expect(
32+
await getByRole('button', {name: 'Named by pseudo element'}),
33+
).toBeDefined()
34+
})
35+
36+
it('supports setting defaultHidden', async () => {
37+
configure({defaultHidden: true})
38+
39+
const {getByRole} = setupBrowser(browser)
40+
41+
expect(await getByRole('button', {name: 'Hidden button'})).toBeDefined()
42+
})
43+
44+
it('supports setting throwSuggestions', async () => {
45+
configure({throwSuggestions: true})
46+
47+
const {getByTestId} = setupBrowser(browser)
48+
49+
await expect(() =>
50+
getByTestId('button-that-should-not-use-testid'),
51+
).rejects.toThrowError(
52+
'TestingLibraryElementError: A better query is available',
53+
)
54+
})
55+
1756
it('works after navigation', async () => {
18-
const {getByText, findByTestId} = setupBrowser(browser)
57+
const {getByText, findByAltText} = setupBrowser(browser)
1958

2059
const goToPageTwoLink = await getByText('Go to Page 2')
2160
await goToPageTwoLink.click()
2261

23-
expect(await findByTestId('page2-thing')).toBeDefined()
62+
expect(await findByAltText('page two thing')).toBeDefined()
2463
})
2564
})

0 commit comments

Comments
 (0)