@testing-library/dom version: 10.4.0
- Testing Framework and version: vitest 2.1.2
- DOM Environment: jsdom 25.0.1
Relevant code or config:
Have two files with following content
// ./foo.test.ts
import { screen } from '@testing-library/dom';
describe('foo suite', () => {
it('foo', async () => {
console.log('foo');
const button = document.createElement('button');
document.body.appendChild(button);
try {
screen.debug();
screen.getByRole('button');
} finally {
button.remove();
}
});
});
// ./bar.test.ts
import { screen } from '@testing-library/dom';
describe('bar suite', () => {
it('bar', async () => {
console.log('bar');
const button = document.createElement('button');
document.body.appendChild(button);
try {
screen.debug();
screen.getByRole('button');
} finally {
button.remove();
}
});
});
What you did:
Run pnpm test run => works
Run pnpm test run -- --no-isolate --no-file-parallelism => one of the tests fail.
What happened:
One of the tests fails, it can't seem to locate the button, yet it's there when calling screen.debug()
bar
<body>
<button />
</body>
/home/projects/vitest-dev-vitest-u1eg7t/test/suite.test.tsx:10:14
8 | document.body.appendChild(button);
9 | try {
> 10 | screen.debug();
| ^
stdout | test/basic.test.tsx > foo suite > foo
foo
<body>
<button />
</body>
/home/projects/vitest-dev-vitest-u1eg7t/test/basic.test.tsx:10:14
8 | document.body.appendChild(button);
9 | try {
> 10 | screen.debug();
| ^
❯ test/basic.test.tsx (1)
❯ foo suite (1)
× foo
✓ test/suite.test.tsx (1)
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
FAIL test/basic.test.tsx > foo suite > foo
TestingLibraryElementError: Unable to find an accessible element with the role "button"
There are no accessible roles. But there might be some inaccessible roles. If you wish to access them, then set the `hidden` option to `true`. Learn more about this here: https://testing-library.com/docs/dom-testing-library/api-queries#byrole
Ignored nodes: comments, script, style
Reproduction:
Stackblitz with reproduction: https://stackblitz.com/edit/vitest-dev-vitest-9xcyxz?file=test%2Fbar.test.ts
You can run pnpm test run and pnpm test run -- --no-isolate --no-file-parallelism to see the bug in action.
Problem description:
Migrating from mocha to vitest, trying to reach similar performance by disabling isolation
Suggested solution:
@testing-library/domversion: 10.4.0Relevant code or config:
Have two files with following content
What you did:
Run
pnpm test run=> worksRun
pnpm test run -- --no-isolate --no-file-parallelism=> one of the tests fail.What happened:
One of the tests fails, it can't seem to locate the button, yet it's there when calling
screen.debug()Reproduction:
Stackblitz with reproduction: https://stackblitz.com/edit/vitest-dev-vitest-9xcyxz?file=test%2Fbar.test.ts
You can run
pnpm test runandpnpm test run -- --no-isolate --no-file-parallelismto see the bug in action.Problem description:
Migrating from mocha to vitest, trying to reach similar performance by disabling isolation
Suggested solution: