最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

typescript - Failed to resolve component: router-link warning - Stack Overflow

programmeradmin0浏览0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

The 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.

发布评论

评论列表(0)

  1. 暂无评论