So I have this function inside my Vue Component:
function openLink(event: Event, url: string, type: string) {
switch (type) {
case 'onetype':
case 'twotype':
event.preventDefault()
openURLInBrowser(url, '_blank');
break
}
}
I am writing my unit test with Vitest. I can easily test, if openLink
have been called:
const wrapper = shallowMount(MyLinks, {
propsData: {
myLinks: linkDataStructure
}
})
const a = wrapper.find('a');
const openLink= vi.spyOn(wrapper.vm, 'openLink')
await a.trigger('click');
expect(openLink).toHaveBeenCalled()
This works great. Now I need to test the case, if type is onetype
, the method openURLInBrowser
is called. So basically the switchcase inside the openLink function.
If I use following, I get: openURLInBrowser does not exist.
const openLink= vi.spyOn(wrapper.vm, 'openURLInBrowser')
How can I access this method inside the function to test it?
Note: The function openURLInBrowser is imported from a openURLInBrowser.ts
-File.