// test/CustomCard.spec.js// LibrariesimportVuefrom'vue'importVuetifyfrom'vuetify'// ComponentsimportCustomCardfrom'@/components/CustomCard'// Utilitiesimport{createLocalVue,mount}from'@vue/test-utils'describe('CustomCard.vue',()=>{constlocalVue=createLocalVue()letvuetifybeforeEach(()=>{vuetify=newVuetify()})it('should have a custom title and match snapshot',()=>{constwrapper=mount(CustomCard,{localVue,vuetify,propsData:{title:'Foobar'},})// With jest we can create snapshot files of the HTML outputexpect(wrapper.html()).toMatchSnapshot()// We could also verify this differently// by checking the text contentconsttitle=wrapper.find('.v-card__title > span')expect(title.text()).toBe('Foobar')})it('should emit an event when the action v-btn is clicked',()=>{constwrapper=mount(CustomCard,{localVue,vuetify,propsData:{title:'Foobar'},})constevent=jest.fn()constbutton=wrapper.find('.v-btn')// Here we bind a listener to the wrapper// instance to catch our custom event// https://vuejs.org/v2/api/#Instance-Methods-Eventswrapper.vm.$on('action-btn:clicked',event)expect(event).toHaveBeenCalledTimes(0)// Simulate a click on the buttonbutton.trigger('click')// Ensure that our mock event was calledexpect(event).toHaveBeenCalledTimes(1)})})