]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
test(view): test named views
authorEduardo San Martin Morote <posva13@gmail.com>
Mon, 1 Jul 2019 16:31:35 +0000 (18:31 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Mon, 1 Jul 2019 16:31:35 +0000 (18:31 +0200)
__tests__/router-view.spec.js

index 1c1ea358c7e18e5c5fbf152b2392d26d6893335c..0e01a28429e8c3493d7a32928bcd206d219940ca 100644 (file)
@@ -22,6 +22,16 @@ const routes = {
     // meta: {},
     matched: [{ components: { default: components.Home }, path: '/' }],
   },
+  named: {
+    fullPath: '/',
+    name: undefined,
+    path: '/',
+    query: {},
+    params: {},
+    hash: '',
+    // meta: {},
+    matched: [{ components: { foo: components.Foo }, path: '/' }],
+  },
 }
 
 describe('RouterView', () => {
@@ -33,10 +43,15 @@ describe('RouterView', () => {
   /**
    *
    * @param {RouteLocationNormalized} $route
+   * @param {Object} [props]
    */
-  function factory($route) {
+  function factory($route, props = {}) {
     // @ts-ignore cannot mount functional component?
     const wrapper = mount(RouterView, {
+      context: {
+        // https://github.com/vuejs/vue-test-utils/issues/918
+        props,
+      },
       mocks: { $route },
     })
     return wrapper
@@ -46,4 +61,9 @@ describe('RouterView', () => {
     const wrapper = factory(routes.root)
     expect(wrapper.html()).toMatchInlineSnapshot(`"<div>Home</div>"`)
   })
+
+  it('displays named views', async () => {
+    const wrapper = factory(routes.named, { name: 'foo' })
+    expect(wrapper.html()).toMatchInlineSnapshot(`"<div>Foo</div>"`)
+  })
 })