Skip to content

can't use vuetify before rending a component #113

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

Closed
nikravi opened this issue Nov 15, 2019 · 5 comments
Closed

can't use vuetify before rending a component #113

nikravi opened this issue Nov 15, 2019 · 5 comments
Labels
bug Something isn't working

Comments

@nikravi
Copy link

nikravi commented Nov 15, 2019

Describe the bug
I would like to add vuetify to vue before rending a component that uses vuetify components, so that the render is successful

To Reproduce

  1. create a component that uses <v-btn>Ok</v-btn>, making sure it renders correctly in browser (follow vuetify instructions)
  2. write unit test for it. Classic example using the vue/testing-utils:
import { createLocalVue, mount, shallowMount } from '@vue/test-utils'
import Home from '@/components/Home.vue'
import vuetify from "vuetify"

describe('Home.vue', () => {
  let wrapper;
  let title = 'Weather App'
  beforeEach(()=>{
    const localVue = createLocalVue()
    localVue.use(vuetify)

    wrapper = shallowMount(Home, {
      localVue // this is important
    });
  })

vuew/test-utils exposes createLocalVue, which testing library is not using. There is no way to pass localVue to the "render" method of testing-library.

  1. unit test code using the testing-library
import { render, fireEvent } from '@testing-library/vue'
// import { createLocalVue} from '@vue/test-utils'

import UserForm from "@/components/UserForm.vue";
// import vuetify from "vuetify"

test('properly handles v-model', async () => {
  // const localVue = createLocalVue()
  // localVue.use(vuetify)

  const { getByLabelText, getByText } = render(UserForm) // no way to pass "localVue"
..
})

fails with

 console.error node_modules/vue/dist/vue.runtime.common.dev.js:621
    [Vue warn]: Unknown custom element: <v-btn> - did you register the component correctly? For recursive components, make sure to provide the "name" option.

Expected behavior
Should be able to load vuetify to the vue before rending a component.

Related information:

  • @testing-library/vue version: 4.1.0
  • Vue version: 2.6.10
  • node version: 11.x
  • npm (or yarn) version:
@nikravi nikravi added the bug Something isn't working label Nov 15, 2019
@nikravi
Copy link
Author

nikravi commented Nov 15, 2019

ok, I found the fix. The trick was to add

import Vue from "vue";
import Vuetify from "vuetify";
Vue.use(Vuetify);

and then the render() works without warnings.

@nikravi nikravi closed this as completed Nov 15, 2019
@afontcu
Copy link
Member

afontcu commented Nov 17, 2019

@mediafreakch
Copy link
Contributor

@afontcu I have the problem that with your example, child components of the tested component don't have access to store anymore. For them it is undefined. Any idea how to fix?

@afontcu
Copy link
Member

afontcu commented Mar 3, 2020

Hi @mediafreakch! Would you mind opening up a new issue with some reproduction links or repos?

Thank you! 🙌

@mediafreakch
Copy link
Contributor

@afontcu #122

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants