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

expect().toContainHTML() doesn't work #408

Open
VSlobolinskyi opened this issue Oct 8, 2021 · 4 comments
Open

expect().toContainHTML() doesn't work #408

VSlobolinskyi opened this issue Oct 8, 2021 · 4 comments

Comments

@VSlobolinskyi
Copy link

VSlobolinskyi commented Oct 8, 2021

  • @testing-library/jest-dom version: 5.14.1
  • node version: 14.15.4
  • npm version: 6.14.13
  • react-testing-library version: 11.2.7

Relevant code or config:

You could find everything in the repository in the todo.test.js file.

What you did:

Run npm run test.

What happened:

image

Reproduction:

Use the project from this repo, and change @testing-library/jest-dom to version: 5.14.1
https://github.com/VSlobolinskyi/react_testing

Problem description:

One of the core functionalities of jest is unavailable

Suggested solution:

Reference @testing-library/jest-dom: 5.11.8, this version doesn't have this bug. I use it in the repository(5.11.9 already has this bug)

@VSlobolinskyi VSlobolinskyi changed the title expect().toContainHTML() doesn't work expect().toContainHTML() doesn't work Oct 8, 2021
@DevHusariaSolutions
Copy link

DevHusariaSolutions commented Jul 10, 2022

expect(element).not.toContainHTML()
    Expected:

    Received:
      <div data-testid=" (...)

Same for me. I just wanted to check is div not empty...

@vincent-thomas
Copy link

Vs code doesn't register any of the extra methods, but vitest registeres them?
Screenshot 2022-07-10 125705
Screenshot 2022-07-10 125649

@vincent-thomas
Copy link

Vs code doesn't register any of the extra methods, but vitest registeres them?
Screenshot 2022-07-10 125705
Screenshot 2022-07-10 125649

Whops fixed it, had to install the jest-dom types

@AndersonSMed
Copy link

AndersonSMed commented Jul 21, 2022

Hello @VSlobolinskyi, I've seen that you are doing an assert using only the opening tag <strike> as the input to the toContainHTML matcher. What happens is that, from version 5.11.10 on, this matcher was updated so it could normalize any given html string (as you can see on this issue) and now when you do something like toContainHTML('<strike>'), the normalization makes the matcher looks for the existence of a <strike></strike> HTML in your rendered component. IMHO the normalization behavior looks more correctly then the previous one, as you were passing a invalid HTML string to the toContainHTML in first place.

Also, I would recommend you to replace the usage of this matcher by another one that mimics the way the user perceives the app, as it would fit more in the philosophy behind jest-dom (this is also an advice the maintainers give in the README).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants