react-testing-library version: 7.0.0react version: 16.8.3node version: 11.14npm (or yarn) version: 1.15.2import React from "react";
import { render, cleanup } from "react-testing-library";
export const Parent = ({ children }) => {
return <div>{children}</div>;
};
describe("<Parent />", () => {
const childElement = <div>Child</div>;
const { debug } = render(<Parent>{childElement}</Parent>);
describe("<Parent /> Rendering", () => {
afterEach(cleanup);
it("should return HTML Snapshot", () => {
debug();
});
it("should have its child rendered", () => {
debug();
});
});
// Other Irrelevant Tests
});
Testing with two different test specs. Debugging returned two different baseEl renders. Avoiding beforeEach to keep small.
First Test Suite printed
<body>
<div>
<div>
<div>
Child
</div>
</div>
</div>
</body>
The second Test Suite
<body />
https://codesandbox.io/s/j2pl0j5z93
See __test__/hello.js and console log.
Expecting the same body to be printed on the second tests as of the first, unless if I did something wrong, I'd like some docs so I can correct my self next time :)
You shouldn't render outside of a test()/it() block. The JSDOM env is global (shared between tests) and the cleanup in the inner describe() is cleaning up the DOM.
Gotcha! Thanks for clarifying and providing a link
Most helpful comment
You shouldn't render outside of a test()/it() block. The JSDOM env is global (shared between tests) and the cleanup in the inner describe() is cleaning up the DOM.