other: { ...components.Foo, beforeRouteEnter },
},
}
+const ErrorLazyLoad: RouteRecordRaw = {
+ path: '/',
+ component: () => Promise.reject(new Error('custom')),
+}
beforeEach(() => {
beforeRouteEnter.mockReset()
await checkGuards([WrongLazyRoute], 0, 1)
expect('Promise instead of a function').toHaveBeenWarned()
})
+
+ it('rejects if lazy load fails', async () => {
+ await expect(checkGuards([ErrorLazyLoad], 0, 1)).rejects.toHaveProperty(
+ 'message',
+ 'custom'
+ )
+ })
})
await router.push('/foo').catch(spy)
expect(spy).toHaveBeenCalled()
- expect(console.error).toHaveBeenCalledWith(error)
+ expect(spy).toHaveBeenLastCalledWith(error)
expect(router.currentRoute.value).toMatchObject({
path: '/',
const spy = jest.fn()
parent.resolve()
- child.reject()
+ const error = new Error()
+ child.reject(error)
await router.push('/foo').catch(spy)
- expect(spy).toHaveBeenCalledWith(expect.any(Error))
+ expect(spy).toHaveBeenCalledWith(error)
expect(router.currentRoute.value).toMatchObject({
path: '/',
`Component "${name}" in record with path "${record.path}" is a function that does not return a Promise. If you were passing a functional component, make sure to add a "displayName" to the component. This will break in production if not fixed.`
)
componentPromise = Promise.resolve(componentPromise as RouteComponent)
- } else {
- // display the error if any
- componentPromise = componentPromise.catch(console.error)
}
guards.push(() =>