Trouble with component testing and vitest-browser-vue
#14858
Replies: 2 comments
|
I tried it again today and it seems to work fine. Not sure why I was having trouble. Closing all posts. |
|
This To resolve this, you can import import { render } from "vitest-browser-vue/pure";
test("Component 1", async () => {
await render(Component1, {
props: { items: ["item one", "item two", "item three"] },
});
});
test("Component 2", async () => {
await render(Component2, {
props: { items: ["item one", "item two"] },
});
});If you still encounter cleanup issues with specific component lifecycles, you can also run manual cleanup/unmount in an |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi all,
I am having some trouble getting the right setup for writing component tests. I have spent considerable effort getting familiar with the vue testing ecosystem and came up with a setup involving Vitest and
vitest-browser-vue.vitest-browser-vueis simply a component testing utility that uses Testing Library principles and makes use of Vitest's supposedly powerful browser mode. I am using Playwright as myproviderin the vitest configuration file and chromium as my browserinstance.The
vitest-browser-vuedocs are more or less clear on how to write a simple component test. I therefore created two simple components and wrote the folllowing tests:When I launch the test suite a browser window opens, showing me the Vitest browser mode UI. The first test runs and passes. The second test fails with the following error:
I had conversations with a number of LLMs (google AI, Claude and ChatGPT) but couldn't quite get to the bottom of how to fix this. I also made an active effort to reach out to the community:
vitest-browser-vuegithube repo: linkIt has been three days and I have not gotten any response as of yet. The fact I cannot run two consecutive tests on two separate components really undermines the whole point of using a library like
vitest-browser-vuein my opinion, so I am pretty sure I am doing something wrong on my end. Has anyone usedvitest-browser-vuein the past to test their components? How did you do it?All reactions