import { mockWarn } from 'jest-mock-warn'
import { createMemoryHistory, createRouter } from '../src'
-import { defineComponent, FunctionalComponent, h } from 'vue'
+import {
+ defineAsyncComponent,
+ defineComponent,
+ FunctionalComponent,
+ h,
+} from 'vue'
let component = defineComponent({})
expect('"/foo" is a Promise instead of a function').toHaveBeenWarned()
})
+ it('warns if use defineAsyncComponent in routes', async () => {
+ const router = createRouter({
+ history: createMemoryHistory(),
+ // simulates import('./component.vue')
+ routes: [
+ {
+ path: '/foo',
+ component: defineAsyncComponent(() => Promise.resolve({})),
+ },
+ ],
+ })
+ await router.push('/foo')
+ expect(
+ `Component "default" in record with path "/foo" is defined using "defineAsyncComponent()". Write "() => import('./MyPage.vue')" instead of "defineAsyncComponent(() => import('./MyPage.vue'))"`
+ ).toHaveBeenWarned()
+ })
+
it('warns if no route matched', async () => {
const router = createRouter({
history: createMemoryHistory(),
)
let promise = rawComponent
rawComponent = () => promise
+ } else if (
+ (rawComponent as any).__asyncLoader &&
+ guardType === 'beforeRouteEnter'
+ ) {
+ warn(
+ `Component "${name}" in record with path "${record.path}" is defined ` +
+ `using "defineAsyncComponent()". ` +
+ `Write "() => import('./MyPage.vue')" instead of ` +
+ `"defineAsyncComponent(() => import('./MyPage.vue'))".`
+ )
}
}