Skip to content

Commit f5439d8

Browse files
Merge branch 'main' into main
2 parents f1299ba + 54bfa48 commit f5439d8

File tree

9 files changed

+33
-9
lines changed

9 files changed

+33
-9
lines changed

Diff for: .all-contributorsrc

+9
Original file line numberDiff line numberDiff line change
@@ -1526,6 +1526,15 @@
15261526
"contributions": [
15271527
"test"
15281528
]
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+
]
15291538
}
15301539
],
15311540
"repoHost": "https://github.com"

Diff for: README.md

+2-1
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="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=tdeschryver" title="Code">💻</a> <a href="https://github.com/testing-library/dom-testing-library/commits?author=tdeschryver" 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>
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>
@@ -332,6 +332,7 @@ Thanks goes to these people ([emoji key][emojis]):
332332
<tr>
333333
<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>
334334
<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>
335336
</tr>
336337
</table>
337338

Diff for: src/__tests__/element-queries.js

+12
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,18 @@ test('getByText ignores script tags by default', () => {
10801080
expect(getAllByText(/hello/i, {ignore: false})).toHaveLength(3)
10811081
})
10821082

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+
10831095
test('get/query input element by current value', () => {
10841096
const {getByDisplayValue, queryByDisplayValue, getByTestId} =
10851097
renderIntoDocument(`

Diff for: src/config.ts

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ let config: InternalConfig = {
3434
eventWrapper: cb => cb(),
3535
// default value for the `hidden` option in `ByRole` queries
3636
defaultHidden: false,
37+
// default value for the `ignore` option in `ByText` queries
38+
defaultIgnore: 'script, style',
3739
// showOriginalStackTrace flag to show the full error stack traces for async errors
3840
showOriginalStackTrace: false,
3941

Diff for: src/pretty-dom.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as prettyFormat from 'pretty-format'
22
import createDOMElementFilter from './DOMElementFilter'
33
import {getUserCodeFrame} from './get-user-code-frame'
44
import {getDocument} from './helpers'
5-
import {DEFAULT_IGNORE_TAGS} from './shared'
5+
import {getConfig} from './config'
66

77
const inNode = () =>
88
typeof process !== 'undefined' &&
@@ -19,8 +19,8 @@ const COMMENT_NODE = 8
1919
function filterCommentsAndDefaultIgnoreTagsTags(value) {
2020
return (
2121
value.nodeType !== COMMENT_NODE &&
22-
// value.nodeType === ELEMENT_NODE => !value.matches(DEFAULT_IGNORE_TAGS)
23-
(value.nodeType !== ELEMENT_NODE || !value.matches(DEFAULT_IGNORE_TAGS))
22+
(value.nodeType !== ELEMENT_NODE ||
23+
!value.matches(getConfig().defaultIgnore))
2424
)
2525
}
2626

Diff for: src/queries/text.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {wrapAllByQueryWithSuggestion} from '../query-helpers'
22
import {checkContainerType} from '../helpers'
3-
import {DEFAULT_IGNORE_TAGS} from '../shared'
43
import {
54
AllByText,
65
GetErrorFunction,
@@ -14,6 +13,7 @@ import {
1413
makeNormalizer,
1514
getNodeText,
1615
buildQueries,
16+
getConfig,
1717
} from './all-utils'
1818

1919
const queryAllByText: AllByText = (
@@ -24,7 +24,7 @@ const queryAllByText: AllByText = (
2424
exact = true,
2525
collapseWhitespace,
2626
trim,
27-
ignore = DEFAULT_IGNORE_TAGS,
27+
ignore = getConfig().defaultIgnore,
2828
normalizer,
2929
} = {},
3030
) => {

Diff for: src/shared.ts

-1
This file was deleted.

Diff for: src/suggestions.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {getNodeText} from './get-node-text'
44
import {getConfig} from './config'
55
import {getImplicitAriaRoles, isInaccessible} from './role-helpers'
66
import {getLabels} from './label-helpers'
7-
import {DEFAULT_IGNORE_TAGS} from './shared'
87

98
const normalize = getDefaultNormalizer()
109

@@ -76,7 +75,7 @@ function canSuggest(currentMethod, requestedMethod, data) {
7675

7776
export function getSuggestedQuery(element, variant = 'get', method) {
7877
// don't create suggestions for script and style elements
79-
if (element.matches(DEFAULT_IGNORE_TAGS)) {
78+
if (element.matches(getConfig().defaultIgnore)) {
8079
return undefined
8180
}
8281

Diff for: types/config.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ export interface Config {
3636
asyncUtilTimeout: number
3737
computedStyleSupportsPseudoElements: boolean
3838
defaultHidden: boolean
39+
/** default value for the `ignore` option in `ByText` queries */
40+
defaultIgnore: string
3941
showOriginalStackTrace: boolean
4042
throwSuggestions: boolean
4143
/**

0 commit comments

Comments
 (0)