Skip to content

Commit bd68e32

Browse files
committed
Added test for undesired behavior
1 parent d1a54bb commit bd68e32

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/__tests__/element-queries.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,3 +1280,34 @@ it(`should get element by it's label when there are elements with same text`, ()
12801280
`)
12811281
expect(getByLabelText('test 1')).toBeInTheDocument()
12821282
})
1283+
1284+
// TODO: undesired behavior. It should ignore the same element: https://github.com/testing-library/dom-testing-library/pull/907#pullrequestreview-678736288
1285+
test('ByText error message ignores not the same elements as configured in `ignore`', () => {
1286+
const {getByText} = renderIntoDocument(`
1287+
<style>
1288+
.css-selector {
1289+
color: red;
1290+
}
1291+
</style>
1292+
<div class="css-selector"></div>
1293+
`)
1294+
1295+
expect(() =>
1296+
getByText('.css-selector', {selector: 'style', ignore: 'script'}),
1297+
).toThrowErrorMatchingInlineSnapshot(`
1298+
"Unable to find an element with the text: .css-selector. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.
1299+
1300+
Ignored nodes: comments, <script />, <style />
1301+
<body>
1302+
1303+
1304+
1305+
1306+
<div
1307+
class="css-selector"
1308+
/>
1309+
1310+
1311+
</body>"
1312+
`)
1313+
})

0 commit comments

Comments
 (0)