Search code examples
javascriptunit-testingjestjsvuejs3quasar-framework

"Cannot read property 'value' of undefined" error - Vue 3 and Quasar component tested with Jest.js


I have to test a component in the application Vue 3 and Quasar with Webpack. This is an example of my test:

import MyComponent from "./MyComponent.vue";
import { mount } from '@vue/test-utils';
import { installQuasarPlugin } from '@quasar/quasar-app-extention-testing-unit-jest'

installQuasarPlugin();

describe('Deployment of MyComponent', () => {
    const wrapper = mount(MyComponent)
    const toolbar = wrapper.findComponent({name: 'QToolbar'}) 

    it('MyComponent renders correctly', () => {
        
        expect(toolbar.exist()).toBe(true)

    })

});

When I run the test I have the error: "Cannot read property 'value' of undefined" and error is shown in const wrapper when I mount the component. I've written other tests in the same way, which works well.


Solution

  • I've changed a little my script like this:

    import MyComponent from "./MyComponent.vue";
    import { mount } from '@vue/test-utils';
    
    describe('Deployment of MyComponent', () => {
        const wrapper = mount(MyComponent)
    
        it('MyComponent renders correctly', () => {
            
            expect(wrapper.exist()).toBe(true)
    
        })
    
    });
    

    I've removed installQuasarPlugin() and tests work but in the console, I have a warning like this: "Filed to resolve component: q-toolbar, If this is a native custom element, make sure to exclude it from component resolution via compilerOptions.isCustomelement."

    So I resolve it only partially