START_LOCATION_NORMALIZED,
RouteLocationNormalized,
} from '../src/types'
+import { ref, markNonReactive } from 'vue'
+import { mount } from './mount'
const routes: Record<string, RouteLocationNormalized> = {
root: {
}
describe('RouterView', () => {
- function factory($route: RouteLocationNormalized, props: any = {}) {
- // @ts-ignore cannot mount functional component?
- const wrapper = mount(RouterView, {
- context: {
- // https://github.com/vuejs/vue-test-utils/issues/918
- props,
- },
- stubs: { RouterView },
- mocks: { $route },
- })
- return wrapper
+ function factory(route: RouteLocationNormalized, props: any = {}) {
+ const router = {
+ currentRoute: ref(markNonReactive(route)),
+ }
+
+ const { app, el } = mount(
+ router as any,
+ {
+ template: `<RouterView :name="name"></RouterView>`,
+ components: { RouterView },
+ setup() {
+ const name = ref(props.name)
+
+ return {
+ name,
+ }
+ },
+ } as any
+ )
+
+ return { app, router, el }
}
- it('displays current route component', async () => {
- const wrapper = factory(routes.root)
- expect(wrapper.html()).toMatchSnapshot()
+ it('displays current route component', () => {
+ const { el } = factory(routes.root)
+ expect(el.innerHTML).toBe(`<div>Home</div>`)
})
- it('displays named views', async () => {
- const wrapper = factory(routes.named, { name: 'foo' })
- expect(wrapper.html()).toMatchSnapshot()
+ it('displays named views', () => {
+ const { el } = factory(routes.named, { name: 'foo' })
+ expect(el.innerHTML).toBe(`<div>Foo</div>`)
})
- it('displays nothing when route is unmatched', async () => {
- const wrapper = factory(START_LOCATION_NORMALIZED)
+ it('displays nothing when route is unmatched', () => {
+ const { el } = factory(START_LOCATION_NORMALIZED)
// NOTE: I wonder if this will stay stable in future releases
- expect(wrapper.html()).toMatchSnapshot()
+ expect(el.innerHTML).toBe(`<!--fragment-0-start--><!--fragment-0-end-->`)
})
- it('displays nested views', async () => {
- const wrapper = factory(routes.nested)
- expect(wrapper.html()).toMatchSnapshot()
+ // TODO: nested routes
+ it.skip('displays nested views', () => {
+ const { el } = factory(routes.nested)
+ expect(el.innerHTML).toBe(`<div><h2>Nested</h2><div>Foo</div></div>`)
})
- it('displays deeply nested views', async () => {
- const wrapper = factory(routes.nestedNested)
- expect(wrapper.html()).toMatchSnapshot()
+ it.skip('displays deeply nested views', () => {
+ const { el } = factory(routes.nestedNested)
+ expect(el.innerHTML).toBe(
+ `<div><h2>Nested</h2><div><h2>Nested</h2><div>Foo</div></div></div>`
+ )
})
})
import { JSDOM, ConstructorOptions } from 'jsdom'
import { NavigationGuard, RouteRecord, MatchedRouteRecord } from '../src/types'
+import { h } from '@vue/runtime-core'
export const tick = (time?: number) =>
new Promise(resolve => {
}
export const components = {
- Home: { render: (h: Function) => h('div', {}, 'Home') },
- Foo: { render: (h: Function) => h('div', {}, 'Foo') },
- Bar: { render: (h: Function) => h('div', {}, 'Bar') },
+ Home: { render: () => h('div', {}, 'Home') },
+ Foo: { render: () => h('div', {}, 'Foo') },
+ Bar: { render: () => h('div', {}, 'Bar') },
Nested: {
- render: (h: Function) =>
- h('div', {}, [h('h2', {}, 'Nested'), h('RouterView')]),
+ render: () => h('div', {}, [h('h2', {}, 'Nested'), h('RouterView')]),
},
}