admin管理员组文章数量:1310519
I've been struggling for days with this one. AI gave me examples of how to do this in vue2 but not in vue3, or it tries but fails.
I've tried mocking this element, stubbing it etc. But most examples and ai answers are correct for vue2 and don't work for vue3.
I've been struggling for days with this one. AI gave me examples of how to do this in vue2 but not in vue3, or it tries but fails.
I've tried mocking this element, stubbing it etc. But most examples and ai answers are correct for vue2 and don't work for vue3.
Share Improve this question edited Feb 3 at 14:08 DarkBee 15.6k8 gold badges72 silver badges117 bronze badges asked Feb 3 at 14:08 imqqmiimqqmi 4732 silver badges9 bronze badges1 Answer
Reset to default 0The key is that you have to set the stub for router-link up in config.global.stubs in vue3:
//setup.ts
import {RouterLinkStub, config } from "@vue/test-utils";
config.global.stubs = {
RouterLink: RouterLinkStub,
}
Add this to the vite.config.mjs file so that the dom is available, and load the setup.ts file on every test run.
//vite.config.mjs
...
test: {
environment: 'jsdom',
// change the path below to to the location of your setup.ts file:
setupFiles: path.resolve(__dirname, './resources/ts/Test/setup.ts'),
}
...
I have router-links in a AuthenticatedLayout.vue file that's included with many 'page' vue files. This resulted in hundreds of warnings during vitest, though the tests all passed. With this method they are gone.
Hopefully this will help others struggling to get rid of those warnings.
本文标签: typescriptFailed to resolve component routerlink warningStack Overflow
版权声明:本文标题:typescript - Failed to resolve component: router-link warning - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741816245a2399096.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论