Skip to content

Commit e85f20a

Browse files
authored
fix: don't fire event on disabled element (#424)
1 parent fc821a2 commit e85f20a

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/wrappers/wrapper.js

+5
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,11 @@ export default class Wrapper implements BaseWrapper {
528528
throwError('you cannot set the target value of an event. See the notes section of the docs for more details—https://vue-test-utils.vuejs.org/en/api/wrapper/trigger.html')
529529
}
530530

531+
// Don't fire event on a disabled element
532+
if (this.attributes().disabled) {
533+
return
534+
}
535+
531536
const modifiers = {
532537
enter: 13,
533538
tab: 9,

test/specs/wrapper/trigger.spec.js

+15
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,21 @@ describeWithShallowAndMount('trigger', (mountingMethod) => {
9393
expect(clickHandler.calledOnce).to.equal(true)
9494
})
9595

96+
it('does not fire on disabled elements', () => {
97+
const clickHandler = sinon.stub()
98+
const TestComponent = {
99+
template: '<button disabled @click="clickHandler"/>',
100+
props: ['clickHandler']
101+
}
102+
const wrapper = mountingMethod(TestComponent, {
103+
propsData: {
104+
clickHandler
105+
}
106+
})
107+
wrapper.trigger('click')
108+
expect(clickHandler.called).to.equal(false)
109+
})
110+
96111
it('handles .prevent', () => {
97112
const TestComponent = {
98113
template: '<input @keydown.enter.prevent="enter">'

0 commit comments

Comments
 (0)