Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

trigger click on native HTML element trigger method but spy does not catch it #1901

Copy link
Copy link
Closed
@jf-niji

Description

@jf-niji
Issue body actions

Subject of the issue

I have a component with a simple link and I want to test that a click on it triggers a method. With Vue test util + jest, the method is called but not the spy.

Version of vue-test-utils : 1.2.0

Steps to reproduce

import { shallowMount } from '@vue/test-utils'

// The component to test
const LinkComponent = {
	template: '<a href="www.google.fr" _target="_blank" @click="trackClick">My link</a>',
	methods: {
		trackClick() {
			console.log('Track click')
		},
	},
}

it('Should call trackClick when link is clicked', async () => {
	const wrapper = shallowMount(LinkComponent)
	const spyTrackClick = jest.spyOn(wrapper.vm, 'trackClick')

	const link = wrapper.find('a')

	await link.trigger('click')

	expect(spyTrackClick).toBeCalled()
})

Expected behaviour

Spy should be called

Actual behaviour

console.log is called and displayed in console & spy is not called
I can reproduce this issue with a ,

& other.

PolThm and jf-niji

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.