react-testing-library version: 9.1.1react version: 16.9.0node version: 10.16.0npm (or yarn) version: N/A// jest.setup.js
import { configure as configureRTL } from '@testing-library/react';
configureRTL({ testIdAttribute: 'data-test-id' });
// some-component.test.js
it('test 1', () => {
const { getByText } = render(<>Hello</>);
expect(getByText('Hello')).not.toBeNull();
});
it('test 2', () => {
const { getByText } = render(<>Hello</>);
expect(getByText('Hello')).not.toBeNull();
});
Upgraded to v9
Automatic cleanup isn't run which causes tests to break. Seems to be linked caused by the configure fn, when removing it from our setup file cleanup works as expected 馃
When adding
import {render, cleanup} from '@testing-library/react'
afterEach(cleanup)
it works as expected
I wasn't able to get Codesandbox to honor the jest config, so no repro unfortunately.
Cleanup doesn't run
Cleanup should run
Could you make a reproduction here? https://github.com/testing-library/dom-testing-library-template
Ah found the issue while creating the repro, the issue is that we used setupFiles instead of setupFilesAfterEnv for setting the RTL config.
Not sure if this should be considered a bug or not. It's a simple fix once you know whats wrong
Thanks for digging in. It's not a bug. Working as documented 馃榾 glad you worked it out!
@alexandernanberg I'm running into the same issue after upgrading to version 9.1.1
Would you mind sharing your RTL config?
@schreyerpeter The RTL config is in my first comment, do you mean the jest config?
@alexandernanberg Yes, Jest config. Thanks!
I've create a sandbox with the issue, seems it's still remaining
I've create a sandbox with the issue, seems it's still remaining
@artem-galas
-fireEvent.click(getByText(/Submit/i)[0]);
+fireEvent.click(getByText(/Submit/i));
getByText already returns a single element. The error message included that you didn't pass a valid element. Why did you think this relates to cleanup?
Yes, you are right about that error, thanks.
But just try to run all tests once again, and you will get an error.
Found multiple elements with the text: /Submit/i
And you will see that component were render several times

I think that's a bug in codesandbox. Are you seeing this locally?
Just tried that locally, seems everything is fine with the example above.... 馃
But something went wrong with my real-world project... Will try to find out what's wrong.
Thanks for your time. Sorry for the buzz.
Most helpful comment
Yes, you are right about that error, thanks.
But just try to run all tests once again, and you will get an error.
Found multiple elements with the text: /Submit/iAnd you will see that component were render several times
