testing-library / testing-library/testing-library-docs
Usage with Jest's `test.concurrent.each`
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 479
- Forks
- 740
- PR merge metrics
- No merged PRs in 30d
Description
@testing-library/domversion: 13.3.0- Testing Framework and version: jest@28.1.1
- DOM Environment: jsdom
Relevant code or config:
/**
* @jest-environment jsdom
*/
import { render } from "@testing-library/react";
import React from "react";
// this works fine, since we don't run concurrently
test.each([{ param: 1 }, { param: 2 }])("it works $param", ({ param }) => {
const { getByTestId } = render(<div data-testid="test-container">Hello</div>);
expect(getByTestId("test-container")).toBeTruthy();
});
// this won't work though, since it will find multiple DOM nodes with id test-container
test.concurrent.each([{ param: 1 }, { param: 2 }])(
"it works $param",
({ param }) => {
const { getByTestId } = render(
<div data-testid="test-container">Hello</div>
);
expect(getByTestId("test-container")).toBeTruthy();
}
);
;
What you did:
I have a set of tests that are relying on jest's test.concurrent feature, and I would like to be able to run these concurrently using test.concurrent.each. Just switching from test.concurrent to test.concurrent.each doesn't seem to work.
What happened:
The render method seems to add these to the same JSDOM document, causing issues with e.g. getByTestId
TestingLibraryElementError: Found multiple elements by: [data-testid="test-container"]
Reproduction:
See code snippet on top, or this repository: https://github.com/jimmycallin/rtl-concurrent-each
Problem description:
test.concurrent.each is a supported feature in jest, and it would be great to be able to run multiple testing-library tests in parallel using this feature.
Suggested solution:
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked minimal reproduction repository and compare the shown test.each and test.concurrent.each cases under Jest 28.1.1 with @testing-library/dom 13.3.0 and jsdom. Determine whether concurrent rendering can be supported safely, and document or verify the resulting behavior for test.concurrent.each.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100