You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/en/api/wrapper/trigger.md
+13
Original file line number
Diff line number
Diff line change
@@ -36,3 +36,16 @@ wrapper.trigger('click', {
36
36
37
37
expect(clickHandler.called).toBe(true)
38
38
```
39
+
-**Setting the event target:**
40
+
41
+
Under the hood, `trigger` creates an `Event` object and dispatches the event on the Wrapper element.
42
+
43
+
It's not possible edit the `target` value of an `Event` object, so you can't set `target` in the options object.
44
+
45
+
To add an attribute to the `target`, you need to set the value of the Wrapper element before calling `trigger`. You can do this with the `element` property.
throwError('cannot call wrapper.trigger() on a wrapper without an element')
517
517
}
518
518
519
+
if(options.target){
520
+
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')
Copy file name to clipboardExpand all lines: test/unit/specs/mount/Wrapper/trigger.spec.js
+10
Original file line number
Diff line number
Diff line change
@@ -103,6 +103,16 @@ describe('trigger', () => {
103
103
expect(info.calledWith(true)).to.equal(true)
104
104
})
105
105
106
+
it('throws error if options contains a target value',()=>{
107
+
constwrapper=mount({render: (h)=>h('div')})
108
+
constdiv=wrapper.find('div')
109
+
constfn=()=>div.trigger('click',{
110
+
target: {}
111
+
})
112
+
constmessage='[vue-test-utils]: 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'
0 commit comments