const expect = require('expect')
const { default: RouterView } = require('../src/components/View')
const { components, isMocha } = require('./utils')
+const { START_LOCATION_NORMALIZED } = require('../src/types')
/** @typedef {import('../src/types').RouteLocationNormalized} RouteLocationNormalized */
// meta: {},
matched: [{ components: { default: components.Home }, path: '/' }],
},
+ nested: {
+ fullPath: '/a',
+ name: undefined,
+ path: '/a',
+ query: {},
+ params: {},
+ hash: '',
+ // meta: {},
+ matched: [
+ { components: { default: components.Nested }, path: '/' },
+ { components: { default: components.Foo }, path: 'a' },
+ ],
+ },
+ nestedNested: {
+ fullPath: '/a/b',
+ name: undefined,
+ path: '/a/b',
+ query: {},
+ params: {},
+ hash: '',
+ // meta: {},
+ matched: [
+ { components: { default: components.Nested }, path: '/' },
+ { components: { default: components.Nested }, path: 'a' },
+ { components: { default: components.Foo }, path: 'b' },
+ ],
+ },
named: {
fullPath: '/',
name: undefined,
// https://github.com/vuejs/vue-test-utils/issues/918
props,
},
+ stubs: { RouterView },
mocks: { $route },
})
return wrapper
const wrapper = factory(routes.named, { name: 'foo' })
expect(wrapper.html()).toMatchInlineSnapshot(`"<div>Foo</div>"`)
})
+
+ it('displays nothing when route is unmatched', async () => {
+ const wrapper = factory(START_LOCATION_NORMALIZED)
+ // NOTE: I wonder if this will stay stable in future releases
+ expect(wrapper.html()).toMatchInlineSnapshot(`undefined`)
+ })
+
+ it('displays nested views', async () => {
+ const wrapper = factory(routes.nested)
+ expect(wrapper.html()).toMatchInlineSnapshot(
+ `"<div><h2>Nested</h2><div>Foo</div></div>"`
+ )
+ })
+
+ it('displays deeply nested views', async () => {
+ const wrapper = factory(routes.nestedNested)
+ expect(wrapper.html()).toMatchInlineSnapshot(
+ `"<div><h2>Nested</h2><div><h2>Nested</h2><div>Foo</div></div></div>"`
+ )
+ })
})
Home: { render: (h: Function) => h('div', {}, 'Home') },
Foo: { render: (h: Function) => h('div', {}, 'Foo') },
Bar: { render: (h: Function) => h('div', {}, 'Bar') },
+ Nested: {
+ render: (h: Function) =>
+ h('div', {}, [h('h2', {}, 'Nested'), h('RouterView')]),
+ },
}
// allow using a .jest modifider to skip some tests on mocha
// @ts-ignore $route is added by our typings
const route = parent.$route
+ // determine current view depth, also check to see if the tree
+ // has been toggled inactive but kept-alive.
+ let depth = 0
+ // let inactive = false
+ // @ts-ignore
+ while (parent && parent._routerRoot !== parent) {
+ const vnodeData = parent.$vnode && parent.$vnode.data
+ if (vnodeData) {
+ // @ts-ignore
+ if (vnodeData.routerView) {
+ depth++
+ }
+ // if (vnodeData.keepAlive && parent._inactive) {
+ // inactive = true
+ // }
+ }
+ parent = parent.$parent
+ }
+ // @ts-ignore for devtools
+ data.routerViewDepth = depth
+
// TODO: support nested router-views
- const matched = route.matched[0]
+ const matched = route.matched[depth]
// render empty node if no matched route
if (!matched) return h()