Skip to content

Commit 863741a

Browse files
author
Kent C. Dodds
committed
feat(getByText): add style to default ignore
1 parent 2536924 commit 863741a

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ getByText(
297297
exact?: boolean = true,
298298
collapseWhitespace?: boolean = true,
299299
trim?: boolean = true,
300-
ignore?: string|boolean = 'script'
300+
ignore?: string|boolean = 'script, style'
301301
}): HTMLElement
302302
```
303303

src/__tests__/element-queries.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,11 +513,17 @@ test('get throws a useful error message without DOM in Cypress', () => {
513513
})
514514

515515
test('getByText ignores script tags by default', () => {
516-
const {getAllByText} = render('<script>Hello</script><div>Hello</div>')
516+
const {getAllByText} = render(
517+
'<script>Hello</script><div>Hello</div><style>.Hello</style>',
518+
)
517519
const divOnly = getAllByText(/hello/i)
518520
expect(divOnly).toHaveLength(1)
519521
expect(divOnly[0].tagName).toBe('DIV')
520-
expect(getAllByText(/hello/i, {ignore: false})).toHaveLength(2)
522+
const noScript = getAllByText(/hello/i, {ignore: 'script'})
523+
expect(noScript[0].tagName).toBe('DIV')
524+
expect(noScript[1].tagName).toBe('STYLE')
525+
expect(noScript).toHaveLength(2)
526+
expect(getAllByText(/hello/i, {ignore: false})).toHaveLength(3)
521527
})
522528

523529
/* eslint jsx-a11y/label-has-for:0 */

src/queries.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function queryAllByText(
7474
exact = true,
7575
collapseWhitespace = true,
7676
trim = true,
77-
ignore = 'script',
77+
ignore = 'script, style',
7878
} = {},
7979
) {
8080
const matcher = exact ? matches : fuzzyMatches

0 commit comments

Comments
 (0)