Skip to content
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

Suggest using toBeEmptyDOMElement instead of toBeEmpty #284

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/__tests__/to-have-text-content.js
Expand Up @@ -83,12 +83,12 @@ describe('.toHaveTextContent', () => {
)
})

test('when matching with empty string and element with content suggest using toBeEmpty instead', () => {
test('when matching with empty string and element with content, suggest using toBeEmptyDOMElement instead', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why the toThrowError line below did not have to be changed as well. Shouldn't the expected error message change to /toBeEmptyDOMElement()/?

I think it's because there's a mistake in that regular expression. Those parenthesis are not being matched but they are interpreted as an empty group. Can you please change that regexp to be /toBeEmptyDOMElement\(\)/?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch. It slipped past me.

I just changed it. Thanks!

// https://github.com/testing-library/jest-dom/issues/104
const {container} = render('<span>not empty</span>')

expect(() =>
expect(container.querySelector('span')).toHaveTextContent(''),
).toThrowError(/toBeEmpty()/)
).toThrowError(/toBeEmptyDOMElement\(\)/)
})
})
2 changes: 1 addition & 1 deletion src/to-have-text-content.js
Expand Up @@ -25,7 +25,7 @@ export function toHaveTextContent(
'',
),
checkingWithEmptyString
? `Checking with empty string will always match, use .toBeEmpty() instead`
? `Checking with empty string will always match, use .toBeEmptyDOMElement() instead`
: `Expected element ${to} have text content`,
checkWith,
'Received',
Expand Down