Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Jest testing Vuetify v-img

I have a component in which I want to test the size of an v-img is being set, for the life of me I can not figure out what to hook into. I have tried grabbing the span tag that surrounds the code and then doing a > div to get the div that gets generated by vuetify so that I can then get the style attribute and test the size is set properly, but it doesnt seem to want to do that, when I add a .length to it it return 0 every time.

My Vue component (footer.vue)

    <template>
      <span class="footerImagesLayout">
        <v-img 
         :height="easg_logo_height"
         :src="$store.state.app.easg_logo.src"
         :width="easg_logo_width"
        contain
         />
     <v-img 
         :height="oma_logo_height"
         :src="$store.state.app.oma_logo.src"
         :width="oma_logo_width"
        contain
         />
       </div>
    </template>
<script>
   export default {
      data(){
         easg_logo_width: this.$store.state.app.easg_logo.top.width, 
         easg_logo_height: this.$store.state.app.easg_logo.top.height,
         oma_logo_width: this.$store.state.app.oma_logo.top.width,
         oma_logo_width: this.$store.state.app.oma_logo.top.width,
      }
   }
</script>

My test (footer.test.js)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import {shallowMount, createLocalVue} from '@vue/test-utils'
import Vuex from 'vuex';
import Footer from '@components/layouts/default/footer'
import Vuetify from 'vuetify';

const vuetify = new Vuetify();
const localVue = createLocalVue();
localVue.use(Vuex);

describe("Footer tests", ()=> {
  let wrapper;
  let store;
  let state;


beforeEach(() => {
   state= {
     app: {
        easg_logo:{
           src: "~/assets/images/easg.jpg",
           text: "EASG", 
           top:{
             height: 72,
             width: 82
           }
         },
    oma_logo:{
           src: "~/assets/images/oma.jpg",
           text: "OMA", 
           top:{
             height: 72,
             width: 82
           }
         }
      }
}

store = new Vuex.Store({
            modules:{
               state
            }
     })

})

test('store test', ()=> {
   wrapper = shallowMount(Footer, {store, localVue, vuetify})
   console.log(wrapper.findAll('.footerImagesLayout > div').length) // this returns 0
   const a = 'a'
    expect(a).toBe('a')
});

});

>Solution :

You probably want mount instead of shallowMount, since v-img is not rendered but stubbed with shallowMount.

From the documentation: "Like mount, it (shallowMount) creates a Wrapper that contains the mounted and rendered Vue component, but with stubbed child components."

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading