testing-library / vue-testing-library

🦎 Simple and complete Vue.js testing utilities that encourage good testing practices.
http://testing-library.com/vue
MIT License
1.08k stars 110 forks source link

Auto importing Vue Testing Library in test files does not work if project is using TypeScript #319

Closed morcth closed 4 weeks ago

morcth commented 1 month ago

Describe the bug A clear and concise description of what the bug is. I was watching a video of someone using Vue Testing Library amd writing their first test in VS Code. He typed "render" and the intellisense popped up and the TL render was the first on the list... which he chose and the import statement was added automatically to the top of the file. This was not happening for me. My project has Typescript installed and configured. I created a new vue project without Typescript and all else the same and it worked as it did in the video... the Render from TL showed up and I chose it and the import line showed up. It seems that TS can't find the functions from TL until it has already been imported while without TS it only needs to be installed and not imported for intellisense to find.

To Reproduce Steps to reproduce the behavior:

npm create vue@latest Yes to only testing with Vitest npm i -D @testing-library/vue Go to the already created HelloWorld.spec.js New blank first line in test already there Start typing "render" (no quotes of course) Correct library comes up and can be chosen and import statement generates

Do the same thing except on the new project, Yes to Typescript and Vitest start typing render and test-utils render comes up as a choice but not testing-library

Expected behavior

I expect testing-library/vue's render to be a choice and auto import when using typescript like it works without ts.

Screenshots

Screenshot from 2024-08-12 11-56-22

Related information:

Relevant code or config (if any)

Additional context

morcth commented 4 weeks ago

Solved. I added "node_modules" to the include array in my tsconfig.vitest.json. This felt like too much processing though so I looked into it and found out that this worked because my file was explicitly listing types in the compilerOptions -> types array. Instead of including node_modules, it is better to just include @testing-library/vue to the types array.