-
Notifications
You must be signed in to change notification settings - Fork 468
Open
Description
@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:
Metadata
Metadata
Assignees
Labels
No labels