-
Notifications
You must be signed in to change notification settings - Fork 54
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
Clean up document after test is finished #50
Comments
Hey @camdub, That sounds sensible to me, I wonder if we could cleanup before we resolve the promise here: https://github.com/nickcolley/jest-axe/blob/master/index.js#L40 Would love a pull request and I can publish this for you. 👍 |
@NickColley that was my thought too on the best way to do the cleanup. I'll look to make a PR. |
I stumbled upon the same problem recently! Good to see I'm not the only one. 😅 Clearing the content of import React from "react";
import { axe, toHaveNoViolations } from "jest-axe";
import { render } from "react-testing-library";
expect.extend(toHaveNoViolations);
it("should be able to make multiple assertion", async () => {
const { container, getByText } = render(<h1>Hello world!</h1>);
expect(await axe(container.innerHTML)).toHaveNoViolations();
// I think this will fail, since document.body is empty now :(
expect(getByText("Hello world!")).toBeInTheDocument();
}) |
@thomasheyenbrock hmm, I've not published anything yet so we've got time to get this right. Do you have an suggestions on an alternative way to solve this problem? |
I proposed a solution in #52 |
Published as version 3.1.1 thanks again. |
Note, if you're using |
@kentcdodds if you want to feel free to open a PR to update the readme with that advice |
Since this matcher appends the rendered content to the document (i.e.,
document.body.innerHTML = html
), I noticed that other tests that render to the document viareact-testing-library
cause there to be two instances of the component in the tree.To avoid this, I added the following:
However, it seems like this would best be handled by
jest-axe
itself. I can create a PR if needed.The text was updated successfully, but these errors were encountered: