-
Notifications
You must be signed in to change notification settings - Fork 668
/
wrapper.js
885 lines (758 loc) · 22.6 KB
/
wrapper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
// @flow
import pretty from 'pretty'
import getSelector from './get-selector'
import {
REF_SELECTOR,
FUNCTIONAL_OPTIONS,
VUE_VERSION,
DOM_SELECTOR
} from 'shared/consts'
import WrapperArray from './wrapper-array'
import ErrorWrapper from './error-wrapper'
import {
throwError,
getCheckedEvent,
isPhantomJS,
nextTick,
warn,
warnDeprecated,
isVueWrapper,
keys
} from 'shared/util'
import { isPlainObject } from 'shared/validators'
import { isElementVisible } from 'shared/is-visible'
import find from './find'
import createWrapper from './create-wrapper'
import { recursivelySetData } from './recursively-set-data'
import { matches } from './matches'
import createDOMEvent from './create-dom-event'
import { throwIfInstancesThrew } from './error'
export default class Wrapper implements BaseWrapper {
+vnode: VNode | null;
+vm: Component | void
_emitted: { [name: string]: Array<Array<any>> }
_emittedByOrder: Array<{ name: string, args: Array<any> }>;
+element: Element;
+options: WrapperOptions
isFunctionalComponent: boolean
rootNode: VNode | Element
selector: Selector | void
constructor(
node: VNode | Element,
options: WrapperOptions,
isVueWrapper?: boolean
) {
const vnode = node instanceof Element ? null : node
const element = node instanceof Element ? node : node.elm
// Prevent redefine by VueWrapper
if (!isVueWrapper) {
// $FlowIgnore : issue with defineProperty
Object.defineProperty(this, 'rootNode', {
get: () => vnode || element,
set: () => throwError('wrapper.rootNode is read-only')
})
// $FlowIgnore
Object.defineProperty(this, 'vnode', {
get: () => vnode,
set: () => throwError('wrapper.vnode is read-only')
})
// $FlowIgnore
Object.defineProperty(this, 'element', {
get: () => element,
set: () => throwError('wrapper.element is read-only')
})
// $FlowIgnore
Object.defineProperty(this, 'vm', {
get: () => undefined,
set: () => throwError('wrapper.vm is read-only')
})
}
const frozenOptions = Object.freeze(options)
// $FlowIgnore
Object.defineProperty(this, 'options', {
get: () => frozenOptions,
set: () => throwError('wrapper.options is read-only')
})
if (
this.vnode &&
(this.vnode[FUNCTIONAL_OPTIONS] || this.vnode.functionalContext)
) {
this.isFunctionalComponent = true
}
}
/**
* Prints warning if component is destroyed
*/
__warnIfDestroyed() {
if (!this.exists()) {
warn('Operations on destroyed component are discouraged')
}
}
at(): void {
this.__warnIfDestroyed()
throwError('at() must be called on a WrapperArray')
}
/**
* Returns an Object containing all the attribute/value pairs on the element.
*/
attributes(key?: string): { [name: string]: string } | string {
this.__warnIfDestroyed()
const attributes = this.element.attributes
const attributeMap = {}
for (let i = 0; i < attributes.length; i++) {
const att = attributes.item(i)
attributeMap[att.localName] = att.value
}
return key ? attributeMap[key] : attributeMap
}
/**
* Returns an Array containing all the classes on the element
*/
classes(className?: string): Array<string> | boolean {
this.__warnIfDestroyed()
const classAttribute = this.element.getAttribute('class')
let classes = classAttribute ? classAttribute.split(' ') : []
// Handle converting cssmodules identifiers back to the original class name
if (this.vm && this.vm.$style) {
const cssModuleIdentifiers = keys(this.vm.$style).reduce((acc, key) => {
// $FlowIgnore
const moduleIdent = this.vm.$style[key]
if (moduleIdent) {
acc[moduleIdent.split(' ')[0]] = key
}
return acc
}, {})
classes = classes.map(name => cssModuleIdentifiers[name] || name)
}
return className ? !!(classes.indexOf(className) > -1) : classes
}
/**
* Checks if wrapper contains provided selector.
* @deprecated
*/
contains(rawSelector: Selector): boolean {
warnDeprecated(
'contains',
'Use `wrapper.find`, `wrapper.findComponent` or `wrapper.get` instead'
)
this.__warnIfDestroyed()
const selector = getSelector(rawSelector, 'contains')
const nodes = find(this.rootNode, this.vm, selector)
return nodes.length > 0
}
/**
* Calls destroy on vm
*/
destroy(): void {
if (!this.vm && !this.isFunctionalComponent) {
throwError(
`wrapper.destroy() can only be called on a Vue instance or ` +
`functional component.`
)
}
if (this.element.parentNode) {
this.element.parentNode.removeChild(this.element)
}
if (this.vm) {
// $FlowIgnore
this.vm.$destroy()
throwIfInstancesThrew(this.vm)
}
}
/**
* Returns an object containing custom events emitted by the Wrapper vm
*/
emitted(
event?: string
): Array<Array<any>> | { [name: string]: Array<Array<any>> } {
if (!this._emitted && !this.vm) {
throwError(`wrapper.emitted() can only be called on a Vue instance`)
}
if (event) {
return this._emitted[event]
}
return this._emitted
}
/**
* Returns an Array containing custom events emitted by the Wrapper vm
* @deprecated
*/
emittedByOrder(): Array<{ name: string, args: Array<any> }> {
warnDeprecated('emittedByOrder', 'Use `wrapper.emitted` instead')
if (!this._emittedByOrder && !this.vm) {
throwError(
`wrapper.emittedByOrder() can only be called on a Vue instance`
)
}
return this._emittedByOrder
}
/**
* Utility to check wrapper exists.
*/
exists(): boolean {
if (this.vm) {
return !!this.vm && !this.vm._isDestroyed
}
return true
}
filter() {
throwError('filter() must be called on a WrapperArray')
}
/**
* Gets first node in tree of the current wrapper that
* matches the provided selector.
*/
get(rawSelector: Selector): Wrapper {
this.__warnIfDestroyed()
const found = this.find(rawSelector)
if (found instanceof ErrorWrapper) {
throw new Error(`Unable to find ${rawSelector} within: ${this.html()}`)
}
return found
}
/**
* Gets first node in tree of the current wrapper that
* matches the provided selector.
*/
getComponent(rawSelector: Selector): Wrapper {
this.__warnIfDestroyed()
const found = this.findComponent(rawSelector)
if (found instanceof ErrorWrapper) {
throw new Error(`Unable to get ${rawSelector} within: ${this.html()}`)
}
return found
}
/**
* Finds first DOM node in tree of the current wrapper that
* matches the provided selector.
*/
find(rawSelector: Selector): Wrapper | ErrorWrapper {
this.__warnIfDestroyed()
const selector = getSelector(rawSelector, 'find')
if (selector.type !== DOM_SELECTOR) {
warnDeprecated(
'finding components with `find` or `get`',
'Use `findComponent` and `getComponent` instead'
)
}
return this.__find(rawSelector, selector)
}
/**
* Finds first component in tree of the current wrapper that
* matches the provided selector.
*/
findComponent(rawSelector: Selector): Wrapper | ErrorWrapper {
this.__warnIfDestroyed()
const selector = getSelector(rawSelector, 'findComponent')
return this.__find(rawSelector, selector)
}
__find(rawSelector: Selector, selector: Object): Wrapper | ErrorWrapper {
const node = find(this.rootNode, this.vm, selector)[0]
if (!node) {
return new ErrorWrapper(rawSelector)
}
const wrapper = createWrapper(node, this.options)
wrapper.selector = rawSelector
return wrapper
}
/**
* Finds DOM elements in tree of the current wrapper that matches
* the provided selector.
*/
findAll(rawSelector: Selector): WrapperArray {
this.__warnIfDestroyed()
const selector = getSelector(rawSelector, 'findAll')
if (selector.type !== DOM_SELECTOR) {
warnDeprecated(
'finding components with `findAll`',
'Use `findAllComponents` instead'
)
}
return this.__findAll(rawSelector, selector)
}
/**
* Finds components in tree of the current wrapper that matches
* the provided selector.
*/
findAllComponents(rawSelector: Selector): WrapperArray {
this.__warnIfDestroyed()
const selector = getSelector(rawSelector, 'findAll')
return this.__findAll(rawSelector, selector, isVueWrapper)
}
__findAll(
rawSelector: Selector,
selector: Object,
filterFn: Function = () => true
): WrapperArray {
const nodes = find(this.rootNode, this.vm, selector)
const wrappers = nodes
.map(node => {
// Using CSS Selector, returns a VueWrapper instance if the root element
// binds a Vue instance.
const wrapper = createWrapper(node, this.options)
wrapper.selector = rawSelector
return wrapper
})
.filter(filterFn)
const wrapperArray = new WrapperArray(wrappers)
wrapperArray.selector = rawSelector
return wrapperArray
}
/**
* Returns HTML of element as a string
*/
html(): string {
this.__warnIfDestroyed()
return pretty(this.element.outerHTML)
}
/**
* Checks if node matches selector or component definition
*/
is(rawSelector: Selector): boolean {
this.__warnIfDestroyed()
const selector = getSelector(rawSelector, 'is')
if (selector.type === DOM_SELECTOR) {
warnDeprecated(
'checking tag name with `is`',
'Use `element.tagName` instead'
)
}
if (selector.type === REF_SELECTOR) {
throwError('$ref selectors can not be used with wrapper.is()')
}
return matches(this.rootNode, selector)
}
/**
* Checks if node is empty
* @deprecated
*/
isEmpty(): boolean {
warnDeprecated(
'isEmpty',
'Consider a custom matcher such as those provided in jest-dom: https://github.com/testing-library/jest-dom#tobeempty. ' +
'When using with findComponent, access the DOM element with findComponent(Comp).element'
)
this.__warnIfDestroyed()
if (!this.vnode) {
return this.element.innerHTML === ''
}
const nodes = []
let node = this.vnode
let i = 0
while (node) {
if (node.child) {
nodes.push(node.child._vnode)
}
node.children &&
node.children.forEach(n => {
nodes.push(n)
})
node = nodes[i++]
}
return nodes.every(n => n.isComment || n.child)
}
/**
* Checks if node is visible
*/
isVisible(): boolean {
this.__warnIfDestroyed()
return isElementVisible(this.element)
}
/**
* Checks if wrapper is a vue instance
* @deprecated
*/
isVueInstance(): boolean {
warnDeprecated(`isVueInstance`)
this.__warnIfDestroyed()
return !!this.vm
}
/**
* Returns name of component, or tag name if node is not a Vue component
* @deprecated
*/
name(): string {
warnDeprecated(`name`)
this.__warnIfDestroyed()
if (this.vm) {
return (
this.vm.$options.name ||
// compat for Vue < 2.3
(this.vm.$options.extendOptions && this.vm.$options.extendOptions.name)
)
}
if (!this.vnode) {
return this.element.tagName
}
return this.vnode.tag
}
/**
* Prints a simple overview of the wrapper current state
* with useful information for debugging
* @deprecated
*/
overview(): void {
warnDeprecated(`overview`)
this.__warnIfDestroyed()
if (!this.vm) {
throwError(`wrapper.overview() can only be called on a Vue instance`)
}
const identation = 4
const formatJSON = (json: any, replacer: Function | null = null) =>
JSON.stringify(json, replacer, identation).replace(/"/g, '')
const visibility = this.isVisible() ? 'Visible' : 'Not visible'
const html = this.html()
? this.html().replace(/^(?!\s*$)/gm, ' '.repeat(identation)) + '\n'
: ''
// $FlowIgnore
const data = formatJSON(this.vm.$data)
/* eslint-disable operator-linebreak */
// $FlowIgnore
const computed = this.vm._computedWatchers
? formatJSON(
// $FlowIgnore
...keys(this.vm._computedWatchers).map(computedKey => ({
// $FlowIgnore
[computedKey]: this.vm[computedKey]
}))
)
: // $FlowIgnore
this.vm.$options.computed
? formatJSON(
// $FlowIgnore
...Object.entries(this.vm.$options.computed).map(([key, value]) => ({
// $FlowIgnore
[key]: value()
}))
)
: '{}'
/* eslint-enable operator-linebreak */
const emittedJSONReplacer = (key, value) =>
value instanceof Array
? value.map((calledWith, index) => {
const callParams = calledWith.map(param =>
typeof param === 'object'
? JSON.stringify(param).replace(/"/g, '').replace(/,/g, ', ')
: param
)
return `${index}: [ ${callParams.join(', ')} ]`
})
: value
const emitted = formatJSON(this.emitted(), emittedJSONReplacer)
console.log(
'\n' +
`Wrapper (${visibility}):\n\n` +
`Html:\n${html}\n` +
`Data: ${data}\n\n` +
`Computed: ${computed}\n\n` +
`Emitted: ${emitted}\n`
)
}
/**
* Returns an Object containing the prop name/value pairs on the element
*/
props(key?: string): { [name: string]: any } | any {
if (this.isFunctionalComponent) {
throwError(
`wrapper.props() cannot be called on a mounted functional component.`
)
}
if (!this.vm) {
throwError('wrapper.props() must be called on a Vue instance')
}
this.__warnIfDestroyed()
const props = {}
const keys = this.vm && this.vm.$options._propKeys
if (keys) {
;(keys || {}).forEach(key => {
if (this.vm) {
props[key] = this.vm[key]
}
})
}
if (key) {
return props[key]
}
return props
}
/**
* Checks radio button or checkbox element
* @deprecated
*/
setChecked(checked: boolean = true): Promise<*> {
this.__warnIfDestroyed()
if (typeof checked !== 'boolean') {
throwError('wrapper.setChecked() must be passed a boolean')
}
const tagName = this.element.tagName
// $FlowIgnore
const type = this.attributes().type
const event = getCheckedEvent()
if (tagName === 'INPUT' && type === 'checkbox') {
// $FlowIgnore
if (this.element.checked === checked) {
return nextTick()
}
if (event !== 'click' || isPhantomJS) {
// $FlowIgnore
this.element.checked = checked
}
return this.trigger(event)
}
if (tagName === 'INPUT' && type === 'radio') {
if (!checked) {
throwError(
`wrapper.setChecked() cannot be called with parameter false on a ` +
`<input type="radio" /> element.`
)
}
// $FlowIgnore
if (this.element.checked === checked) {
return nextTick()
}
if (event !== 'click' || isPhantomJS) {
// $FlowIgnore
this.element.selected = true
}
return this.trigger(event)
}
throwError(`wrapper.setChecked() cannot be called on this element`)
return nextTick()
}
/**
* Selects <option></option> element
* @deprecated
*/
setSelected(): Promise<void> {
this.__warnIfDestroyed()
const tagName = this.element.tagName
if (tagName === 'SELECT') {
throwError(
`wrapper.setSelected() cannot be called on select. Call it on one of ` +
`its options`
)
}
if (tagName !== 'OPTION') {
throwError(`wrapper.setSelected() cannot be called on this element`)
}
// $FlowIgnore
if (this.element.selected) {
return nextTick()
}
// $FlowIgnore
this.element.selected = true
// $FlowIgnore
let parentElement = this.element.parentElement
// $FlowIgnore
if (parentElement.tagName === 'OPTGROUP') {
// $FlowIgnore
parentElement = parentElement.parentElement
}
// $FlowIgnore
return createWrapper(parentElement, this.options).trigger('change')
}
/**
* Sets vm data
*/
setData(data: Object): Promise<void> {
if (this.isFunctionalComponent) {
throwError(`wrapper.setData() cannot be called on a functional component`)
}
if (!this.vm) {
throwError(`wrapper.setData() can only be called on a Vue instance`)
}
this.__warnIfDestroyed()
recursivelySetData(this.vm, this.vm, data)
return nextTick()
}
/**
* Sets vm methods
* @deprecated
*/
setMethods(methods: Object): void {
warnDeprecated(
`setMethods`,
`There is no clear migration path for setMethods - Vue does not support arbitrarily replacement of methods, nor should VTU. To stub a complex method extract it from the component and test it in isolation. Otherwise, the suggestion is to rethink those tests`
)
if (!this.vm) {
throwError(`wrapper.setMethods() can only be called on a Vue instance`)
}
this.__warnIfDestroyed()
keys(methods).forEach(key => {
// $FlowIgnore : Problem with possibly null this.vm
this.vm[key] = methods[key]
// $FlowIgnore : Problem with possibly null this.vm
this.vm.$options.methods[key] = methods[key]
})
if (this.vnode) {
const context = this.vnode.context
if (context.$options.render) context._update(context._render())
}
}
/**
* Sets vm props
*/
setProps(data: Object): Promise<void> {
// Validate the setProps method call
if (this.isFunctionalComponent) {
throwError(
`wrapper.setProps() cannot be called on a functional component`
)
}
if (!this.vm) {
throwError(`wrapper.setProps() can only be called on a Vue instance`)
}
// $FlowIgnore : Problem with possibly null this.vm
if (!this.vm.$parent.$options.$_isWrapperParent) {
throwError(
`wrapper.setProps() can only be called for top-level component`
)
}
this.__warnIfDestroyed()
keys(data).forEach(key => {
// Don't let people set entire objects, because reactivity won't work
if (
isPlainObject(data[key]) &&
// $FlowIgnore : Problem with possibly null this.vm
data[key] === this.vm[key]
) {
throwError(
`wrapper.setProps() called with the same object of the existing ` +
`${key} property. You must call wrapper.setProps() with a new ` +
`object to trigger reactivity`
)
}
if (
VUE_VERSION <= 2.3 &&
(!this.vm ||
!this.vm.$options._propKeys ||
!this.vm.$options._propKeys.some(prop => prop === key))
) {
throwError(
`wrapper.setProps() called with ${key} property which ` +
`is not defined on the component`
)
}
// $FlowIgnore : Problem with possibly null this.vm
const parent = this.vm.$parent
parent.$set(parent.vueTestUtils_childProps, key, data[key])
})
return nextTick()
}
/**
* Sets element value and triggers input event
*/
setValue(value: any): Promise<void> {
const tagName = this.element.tagName
// $FlowIgnore
const type = this.attributes().type
this.__warnIfDestroyed()
if (tagName === 'OPTION') {
throwError(
`wrapper.setValue() cannot be called on an <option> element. Use ` +
`wrapper.setSelected() instead`
)
} else if (tagName === 'INPUT' && type === 'checkbox') {
throwError(
`wrapper.setValue() cannot be called on a <input type="checkbox" /> ` +
`element. Use wrapper.setChecked() instead`
)
} else if (tagName === 'INPUT' && type === 'radio') {
throwError(
`wrapper.setValue() cannot be called on a <input type="radio" /> ` +
`element. Use wrapper.setChecked() instead`
)
} else if (tagName === 'SELECT') {
if (Array.isArray(value)) {
// $FlowIgnore
const options = this.element.options
for (let i = 0; i < options.length; i++) {
const option = options[i]
option.selected = value.indexOf(option.value) >= 0
}
} else {
// $FlowIgnore
this.element.value = value
}
this.trigger('change')
return nextTick()
} else if (tagName === 'INPUT' || tagName === 'TEXTAREA') {
// $FlowIgnore
this.element.value = value
this.trigger('input')
// for v-model.lazy, we need to trigger a change event, too.
// $FlowIgnore
if (this.element._vModifiers && this.element._vModifiers.lazy) {
this.trigger('change')
}
return nextTick()
}
throwError(`wrapper.setValue() cannot be called on this element`)
return nextTick()
}
/**
* Return text of wrapper element
*/
text(): string {
this.__warnIfDestroyed()
return this.element.textContent.trim()
}
/**
* Simulates event triggering
*/
__simulateTrigger(type: string, options?: Object): void {
const regularEventTrigger = (type, options) => {
const event = createDOMEvent(type, options)
return this.element.dispatchEvent(event)
}
const focusEventTrigger = (type, options) => {
if (this.element instanceof HTMLElement) {
return this.element.focus()
}
regularEventTrigger(type, options)
}
const triggerProcedureMap = {
focus: focusEventTrigger,
__default: regularEventTrigger
}
const triggerFn = triggerProcedureMap[type] || triggerProcedureMap.__default
return triggerFn(type, options)
}
/**
* Dispatches a DOM event on wrapper
*/
trigger(type: string, options: Object = {}): Promise<void> {
this.__warnIfDestroyed()
if (typeof type !== 'string') {
throwError('wrapper.trigger() must be passed a string')
}
if (options.target) {
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/api/wrapper/trigger.html`
)
}
/**
* Avoids firing events on specific disabled elements
* See more: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/disabled
*/
const supportedTags = [
'BUTTON',
'COMMAND',
'FIELDSET',
'KEYGEN',
'OPTGROUP',
'OPTION',
'SELECT',
'TEXTAREA',
'INPUT'
]
const tagName = this.element.tagName
if (this.attributes().disabled && supportedTags.indexOf(tagName) > -1) {
return nextTick()
}
this.__simulateTrigger(type, options)
return nextTick()
}
}