Describe the bug A clear and concise description of what the bug is.
Since automatically clean up aftereach was implemented, vitest doesn't run the cleanup by default, leaving previously mounted components to be accessed by later tests.
To Reproduce Steps to reproduce the behavior:
npm init vue@latest + vitest + vue-testing-library, refer to screenshot below for code (basically just two tests and last one should fail to get element)
Expected behavior
It's expected that DOM is cleared up automatically after each test without any custom configuration needed, or the setup guide is updated
This is because this library expect afterEach to be globally defined, which is not the case with vitest by default.
So adding this to vite config fixes the issue:
Describe the bug A clear and concise description of what the bug is.
Since automatically clean up aftereach was implemented,
vitest
doesn't run the cleanup by default, leaving previously mounted components to be accessed by later tests.To Reproduce Steps to reproduce the behavior:
npm init vue@latest
+ vitest + vue-testing-library, refer to screenshot below for code (basically just two tests and last one should fail to get element)Expected behavior
It's expected that DOM is cleared up automatically after each test without any custom configuration needed, or the setup guide is updated
Screenshots
Related information:
@testing-library/vue
version: 6.6.1Vue
version: 3.2.45node
version: v16.13.0npm
(oryarn
) version: 8.1.0Relevant code or config (if any)
Additional context
This is because this library expect
afterEach
to be globally defined, which is not the case withvitest
by default. So adding this to vite config fixes the issue: