-
Notifications
You must be signed in to change notification settings - Fork 471
fix: log ignored selectors correctly on error #1141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
eps1lon
merged 3 commits into
testing-library:main
from
robin-drexler:fix-get-element-error
Aug 9, 2022
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,16 @@ | ||
import {configure} from '../config' | ||
import {configure, getConfig} from '../config' | ||
import {render, renderIntoDocument} from './helpers/test-utils' | ||
|
||
// set original config | ||
let originalConfig | ||
beforeAll(() => { | ||
originalConfig = getConfig() | ||
}) | ||
|
||
afterEach(() => { | ||
configure(originalConfig) | ||
}) | ||
|
||
test('query can return null', () => { | ||
const { | ||
queryByLabelText, | ||
|
@@ -35,7 +45,7 @@ test('get throws a useful error message', () => { | |
.toThrowErrorMatchingInlineSnapshot(` | ||
Unable to find a label with the text of: LucyRicardo | ||
|
||
Ignored nodes: comments, <script />, <style /> | ||
Ignored nodes: comments, script, style | ||
<div> | ||
<div /> | ||
</div> | ||
|
@@ -44,15 +54,15 @@ test('get throws a useful error message', () => { | |
.toThrowErrorMatchingInlineSnapshot(` | ||
Unable to find an element with the placeholder text of: LucyRicardo | ||
|
||
Ignored nodes: comments, <script />, <style /> | ||
Ignored nodes: comments, script, style | ||
<div> | ||
<div /> | ||
</div> | ||
`) | ||
expect(() => getByText('LucyRicardo')).toThrowErrorMatchingInlineSnapshot(` | ||
Unable to find an element with the text: LucyRicardo. 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. | ||
|
||
Ignored nodes: comments, <script />, <style /> | ||
Ignored nodes: comments, script, style | ||
<div> | ||
<div /> | ||
</div> | ||
|
@@ -61,31 +71,31 @@ test('get throws a useful error message', () => { | |
.toThrowErrorMatchingInlineSnapshot(` | ||
Unable to find an element with the text: Lucy Ricardo (normalized from 'Lucy Ricardo'). 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. | ||
|
||
Ignored nodes: comments, <script />, <style /> | ||
Ignored nodes: comments, script, style | ||
<div> | ||
<div /> | ||
</div> | ||
`) | ||
expect(() => getByTestId('LucyRicardo')).toThrowErrorMatchingInlineSnapshot(` | ||
Unable to find an element by: [data-testid="LucyRicardo"] | ||
|
||
Ignored nodes: comments, <script />, <style /> | ||
Ignored nodes: comments, script, style | ||
<div> | ||
<div /> | ||
</div> | ||
`) | ||
expect(() => getByAltText('LucyRicardo')).toThrowErrorMatchingInlineSnapshot(` | ||
Unable to find an element with the alt text: LucyRicardo | ||
|
||
Ignored nodes: comments, <script />, <style /> | ||
Ignored nodes: comments, script, style | ||
<div> | ||
<div /> | ||
</div> | ||
`) | ||
expect(() => getByTitle('LucyRicardo')).toThrowErrorMatchingInlineSnapshot(` | ||
Unable to find an element with the title: LucyRicardo. | ||
|
||
Ignored nodes: comments, <script />, <style /> | ||
Ignored nodes: comments, script, style | ||
<div> | ||
<div /> | ||
</div> | ||
|
@@ -94,7 +104,7 @@ test('get throws a useful error message', () => { | |
.toThrowErrorMatchingInlineSnapshot(` | ||
Unable to find an element with the display value: LucyRicardo. | ||
|
||
Ignored nodes: comments, <script />, <style /> | ||
Ignored nodes: comments, script, style | ||
<div> | ||
<div /> | ||
</div> | ||
|
@@ -104,7 +114,7 @@ test('get throws a useful error message', () => { | |
|
||
There are no accessible roles. But there might be some inaccessible roles. If you wish to access them, then set the \`hidden\` option to \`true\`. Learn more about this here: https://testing-library.com/docs/dom-testing-library/api-queries#byrole | ||
|
||
Ignored nodes: comments, <script />, <style /> | ||
Ignored nodes: comments, script, style | ||
<div> | ||
<div /> | ||
</div> | ||
|
@@ -371,7 +381,7 @@ test('label with no form control', () => { | |
expect(() => getByLabelText(/alone/)).toThrowErrorMatchingInlineSnapshot(` | ||
Found a label with the text of: /alone/, however no form control was found associated to that label. Make sure you're using the "for" attribute or "aria-labelledby" attribute correctly. | ||
|
||
Ignored nodes: comments, <script />, <style /> | ||
Ignored nodes: comments, script, style | ||
<div> | ||
<label> | ||
All alone | ||
|
@@ -389,7 +399,7 @@ test('label with "for" attribute but no form control and fuzzy matcher', () => { | |
.toThrowErrorMatchingInlineSnapshot(` | ||
Found a label with the text of: alone, however no form control was found associated to that label. Make sure you're using the "for" attribute or "aria-labelledby" attribute correctly. | ||
|
||
Ignored nodes: comments, <script />, <style /> | ||
Ignored nodes: comments, script, style | ||
<div> | ||
<label | ||
for="foo" | ||
|
@@ -412,7 +422,7 @@ test('label with children with no form control', () => { | |
.toThrowErrorMatchingInlineSnapshot(` | ||
Found a label with the text of: /alone/, however no form control was found associated to that label. Make sure you're using the "for" attribute or "aria-labelledby" attribute correctly. | ||
|
||
Ignored nodes: comments, <script />, <style /> | ||
Ignored nodes: comments, script, style | ||
<div> | ||
|
||
|
||
|
@@ -453,7 +463,7 @@ test('label with non-labellable element', () => { | |
expect(() => getByLabelText(/Label/)).toThrowErrorMatchingInlineSnapshot(` | ||
Found a label with the text of: /Label/, however the element associated with this label (<div />) is non-labellable [https://html.spec.whatwg.org/multipage/forms.html#category-label]. If you really need to label a <div />, you can use aria-label or aria-labelledby instead. | ||
|
||
Ignored nodes: comments, <script />, <style /> | ||
Ignored nodes: comments, script, style | ||
<div> | ||
|
||
|
||
|
@@ -503,7 +513,7 @@ test('multiple labels with non-labellable elements', () => { | |
|
||
Found a label with the text of: /Label/, however the element associated with this label (<p />) is non-labellable [https://html.spec.whatwg.org/multipage/forms.html#category-label]. If you really need to label a <p />, you can use aria-label or aria-labelledby instead. | ||
|
||
Ignored nodes: comments, <script />, <style /> | ||
Ignored nodes: comments, script, style | ||
<div> | ||
|
||
|
||
|
@@ -555,7 +565,7 @@ test('totally empty label', () => { | |
expect(() => getByLabelText('')).toThrowErrorMatchingInlineSnapshot(` | ||
Found a label with the text of: , however no form control was found associated to that label. Make sure you're using the "for" attribute or "aria-labelledby" attribute correctly. | ||
|
||
Ignored nodes: comments, <script />, <style /> | ||
Ignored nodes: comments, script, style | ||
<div> | ||
<label /> | ||
</div> | ||
|
@@ -1092,6 +1102,19 @@ test('the default value for `ignore` can be configured', () => { | |
expect(noStyle[1].tagName).toBe('DIV') | ||
}) | ||
|
||
test('the default value for `ignore` is used in errors', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New test that proves that overriding |
||
configure({defaultIgnore: 'div'}) | ||
|
||
const {getByText} = render('<div>Hello</div>') | ||
|
||
expect(() => getByText(/hello/i)).toThrowErrorMatchingInlineSnapshot(` | ||
Unable to find an element with the text: /hello/i. 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. | ||
|
||
Ignored nodes: comments, div | ||
<div /> | ||
`) | ||
}) | ||
|
||
test('get/query input element by current value', () => { | ||
const {getByDisplayValue, queryByDisplayValue, getByTestId} = | ||
renderIntoDocument(` | ||
|
@@ -1206,7 +1229,7 @@ test('return a proper error message when no label is found and there is an aria- | |
.toThrowErrorMatchingInlineSnapshot(` | ||
Unable to find a label with the text of: LucyRicardo | ||
|
||
Ignored nodes: comments, <script />, <style /> | ||
Ignored nodes: comments, script, style | ||
<div> | ||
<input | ||
aria-labelledby="not-existing-label" | ||
|
@@ -1276,7 +1299,7 @@ test('ByText error message ignores not the same elements as configured in `ignor | |
).toThrowErrorMatchingInlineSnapshot(` | ||
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. | ||
|
||
Ignored nodes: comments, <script />, <style /> | ||
Ignored nodes: comments, script, style | ||
<body> | ||
|
||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure tests don't rely on previous tests changing the config in a certain way.