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

Unit test error #9

Closed
ImmortalDragonm opened this issue May 18, 2018 · 11 comments
Closed

Unit test error #9

ImmortalDragonm opened this issue May 18, 2018 · 11 comments
Labels
enhancement New feature or request

Comments

@ImmortalDragonm
Copy link

@vue/cli: 3.0.0-beta.10
vue-cli-plugin-vuetify: 0.1.3
vuetify: 1.0.16

When i run unit test, i'v got this error message.

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

    console.error node_modules/vue/dist/vue.runtime.common.js:589
    [Vue warn]: Unknown custom element: <v-slide-y-transition> - did you register the component correctly? For recursive components, make sure to provide the "name" option.
    
    (found in <Root>)

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

Step to reproduce:

vue create myapp
cd myapp
vue add vuetify
npm run test:unit
@nekosaur
Copy link
Member

Which options did you select when adding vuetify?

@ImmortalDragonm
Copy link
Author

? Allow Vuetify to replace App.vue and HelloWorld.vue? Yes
? Use custom theme? No
? Use a-la-carte components? No
? Use babel/polyfill? Yes

@nekosaur nekosaur added the enhancement New feature or request label May 18, 2018
@nekosaur
Copy link
Member

nekosaur commented May 18, 2018

I just realized that we don't actually try to modify test setup at all currently. It should probably be an option.

@ImmortalDragonm
Copy link
Author

ImmortalDragonm commented May 18, 2018

I know, that test don't modify, and add option - is good.
But what about warning?
[Vue warn]: Unknown custom element: <v-container> - did you register the component correctly? For recursive components, make sure to provide the "name" option.
How to solve them?

@nekosaur
Copy link
Member

It depends on what test framework you're using. You might have an entry point index.js for your tests where you can do Vue.use(Vuetify). Basically you need to load the vuetify library when running your tests.

@ImmortalDragonm
Copy link
Author

Where is no index.js in jest nor mocha+chai (options in vue create)

@eskemojoe007
Copy link

Running into a similar issue...any solution for jest? I use the cli and am running into these issues.

@eskemojoe007
Copy link

I got this working by using createLocalVue

import { shallowMount, createLocalVue, mount } from '@vue/test-utils';
// import { mount } from '@vue/test-utils';
// eslint-disable-next-line import/no-unresolved
import HelloWorld from '@/components/HelloWorld.vue';
import Vuetify from 'vuetify';

describe('HelloWorld.vue', () => {
  let localVue;
  let wrapper;
  beforeAll(() => {
    localVue = createLocalVue();
    localVue.use(Vuetify, {});
    wrapper = mount(HelloWorld, { localVue });
  });

  it('renders props.msg when passed', () => {
    const msg = 'new message';
    wrapper.setProps({ msg });
    expect(wrapper.html()).toMatch(msg);
    expect(wrapper.props().msg).toMatch(msg);
  });


  it('render props.author when passed', () => {
    const msg = 'new message';

    wrapper.setProps({ author: msg });
    expect(wrapper.html()).toMatch(msg);
    expect(wrapper.props().author).toMatch(msg);
  });
});

Produces:
C:\Users\david\Documents\GitHub\sw_web_app\frontend>npm run test:unit

> [email protected] test:unit C:\Users\david\Documents\GitHub\sw_web_app\frontend
> vue-cli-service test:unit

 PASS  tests/unit/HelloWorld.spec.js
  HelloWorld.vue
    √ renders props.msg when passed (8ms)
    √ render props.author when passed (2ms)

Test Suites: 1 passed, 1 total
Tests:       2 passed, 2 total
Snapshots:   0 total
Time:        3.611s
Ran all test suites.

@arafath-mk
Copy link

import { shallowMount } from '@vue/test-utils';
import HelloWorld from '@/components/HelloWorld.vue';
import Vue from 'vue';
import Vuetify from 'vuetify';

Vue.use(Vuetify);

describe('HelloWorld.vue', () => {
  it('renders props.msg when passed', () => {
    const msg = 'new message';
    const wrapper = shallowMount(HelloWorld, {
      propsData: { msg },
    });
    expect(wrapper.text()).toMatch(msg);
  });
});  

@rustyx
Copy link

rustyx commented Sep 19, 2019

Create a file tests/unit/index.js:

import Vue from 'vue';
import Vuetify from 'vuetify';
Vue.config.productionTip = false;
Vue.use(Vuetify);

Then add to jest.config.js:

  setupFiles: [ '<rootDir>/tests/unit/index.js' ],

@johnleider
Copy link
Member

There is now a section in the documentation dedicated towards explaining how to do this https://vuetifyjs.com/getting-started/unit-testing .

If you have any additional questions, please reach out to us in our Discord community.

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

No branches or pull requests

6 participants