Skip to content

Commit 001179b

Browse files
committed
respect custom ignores
1 parent d0b169a commit 001179b

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/__tests__/suggestions.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,21 @@ afterAll(() => {
1010
configure({throwSuggestions: false})
1111
})
1212

13-
test('dost not suggest for inline script, style', () => {
13+
test('does not suggest for inline script, style', () => {
1414
renderIntoDocument(
1515
`<script data-testid="script">alert('hello')</script><style data-testid="style">.hsuHs{margin:auto}.wFncld{margin-top:3px;color:#9AA0A6;height:20px;width:20px}</style>`,
1616
)
1717

1818
expect(() => screen.getByTestId('script')).not.toThrow()
1919
expect(() => screen.getByTestId('style')).not.toThrow()
2020
})
21+
it('respects ignores', () => {
22+
renderIntoDocument(`<my-thing>foo</my-thing>`)
23+
24+
expect(() =>
25+
screen.queryByText('foo', {ignore: 'my-thing'}),
26+
).not.toThrowError()
27+
})
2128

2229
test('does not suggest when using getByRole', () => {
2330
renderIntoDocument(`<button data-testid="foo">submit</button>`)

src/query-helpers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ const wrapSingleQueryWithSuggestion = (query, queryAllByName, variant) => (
9494
) => {
9595
const element = query(container, ...args)
9696
const [{suggest = getConfig().throwSuggestions} = {}] = args.slice(-1)
97-
if (suggest) {
97+
if (element && suggest) {
9898
const suggestion = getSuggestedQuery(element, variant)
9999
if (suggestion && !queryAllByName.endsWith(suggestion.queryName)) {
100100
throw getSuggestionError(suggestion.toString(), container)
@@ -111,7 +111,7 @@ const wrapAllByQueryWithSuggestion = (query, queryAllByName, variant) => (
111111
const els = query(container, ...args)
112112

113113
const [{suggest = getConfig().throwSuggestions} = {}] = args.slice(-1)
114-
if (suggest) {
114+
if (els.length && suggest) {
115115
// get a unique list of all suggestion messages. We are only going to make a suggestion if
116116
// all the suggestions are the same
117117
const uniqueSuggestionMessages = [

0 commit comments

Comments
 (0)