Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unknown custom element: <router-link> when using mount() #994

Closed
ArmorDarks opened this issue Oct 9, 2018 · 3 comments
Closed

Unknown custom element: <router-link> when using mount() #994

ArmorDarks opened this issue Oct 9, 2018 · 3 comments
Labels

Comments

@ArmorDarks
Copy link

ArmorDarks commented Oct 9, 2018

Version

1.0.0-beta.25

Steps to reproduce

Component Test.js, which uses another component with router-link inside:

import Vue from 'vue'
import Component from 'vue-class-component'

const Card = Component(class Card extends Vue {
  render () {
    return <router-link to='test'>Test</router-link>
  }
})

export default {
  render () {
    return <Card />
  }
}

Given the following test:

// @flow
/* eslint-env jest */

import { mount, createLocalVue, RouterLinkStub } from '@vue/test-utils'
import VueRouter from 'vue-router'

import Test from './Offices'

const localVue = createLocalVue()
localVue.use(VueRouter)

describe('Test.js', () => {
  it('should render with a stub', () => expect(mount(Test , {
    localVue,
    stubs: { 'router-link': RouterLinkStub }
  }).element).toBeDefined())

  it('should render with the router', () => {

    expect(mount(Test , {
      localVue
    }).element).toBeDefined()
  })
})

What is expected?

In both test cases router-link in OfficeCard should be stubbed and tests should pass without errors.

What is actually happening?

Instead, the following error will be logged to the console for both cases:

[Vue warn]: Unknown custom element: <router-link> - did you register the component correctly? For recursive components, make sure to provide the "name" option.

The issue is definitely related to the vue-class-component since the following code will pass without errors:

import Vue from 'vue'
import Component from 'vue-class-component'

const Card = {
  render () {
    return <router-link to='test'>Test</router-link>
  }
}

export default {
  render () {
    return <Card />
  }
}

I assume it is because it directly extends Vue which prevents test-utils from effectively stubbing underlying components.

eddyerburgh added a commit that referenced this issue Nov 25, 2018
Fixes #973
Fixes #994
Fixes #995


BREAKING CHANGE: The tag name rendered by snapshots will use the rendered component tag, rather than the registered component name
@ArmorDarks
Copy link
Author

@eddyerburgh Thanks, however, was it really fixed? I'm still observing the same issue when using vue-class-component

@eddyerburgh
Copy link
Member

The fix will be included in the next beta release, which will before September 15

@DespertaWeb
Copy link

Is it fixed? ???

I'm experiencing the same here:

describe('VHome', () => {
  const wrapper = mount(VHome, {
    stubs: {
      RouterLink: RouterLinkStub,
    },
  })

  it(' - Renders a vue instance', () => {
    expect(shallowMount(VHome).isVueInstance()).toBe(true)
  })

  it(' - Home Has a link to Ships', () => {
    expect(wrapper.find(RouterLinkStub).props().to).toStrictEqual({
      name: 'ships',
    })
  })
})

However if I comment out the first it, it doesn't throw any errors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants