File tree 3 files changed +12
-6
lines changed
3 files changed +12
-6
lines changed Original file line number Diff line number Diff line change 1
1
import { dispatchUIEvent } from '../event'
2
2
import { Config } from '../setup'
3
+ import { isElementType } from '../utils'
3
4
import { prepareSelectionInterceptor } from './selection'
4
5
import { prepareRangeTextInterceptor } from './setRangeText'
5
6
import {
@@ -24,7 +25,7 @@ export function prepareDocument(document: Document) {
24
25
document . addEventListener (
25
26
'focus' ,
26
27
e => {
27
- const el = e . target as Node
28
+ const el = e . target as Element
28
29
29
30
prepareElement ( el )
30
31
} ,
@@ -62,12 +63,12 @@ export function prepareDocument(document: Document) {
62
63
document [ isPrepared ] = isPrepared
63
64
}
64
65
65
- function prepareElement ( el : Node | HTMLInputElement ) {
66
+ function prepareElement ( el : Element ) {
66
67
if ( el [ isPrepared ] ) {
67
68
return
68
69
}
69
70
70
- if ( 'value' in el ) {
71
+ if ( isElementType ( el , [ 'input' , 'textarea' ] ) ) {
71
72
prepareValueInterceptor ( el )
72
73
prepareSelectionInterceptor ( el )
73
74
prepareRangeTextInterceptor ( el )
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ type Params<Prop> = Prop extends anyFunc ? Parameters<Prop> : [Prop]
10
10
type ImplReturn < Prop > = Prop extends anyFunc ? Parameters < Prop > : Prop
11
11
12
12
export function prepareInterceptor <
13
- ElementType extends Node ,
13
+ ElementType extends Element ,
14
14
PropName extends keyof ElementType ,
15
15
> (
16
16
element : ElementType ,
@@ -39,11 +39,14 @@ export function prepareInterceptor<
39
39
40
40
const target = prototypeDescriptor ?. set ? 'set' : 'value'
41
41
42
+ /* istanbul ignore if */
42
43
if (
43
44
typeof prototypeDescriptor ?. [ target ] !== 'function' ||
44
45
( prototypeDescriptor [ target ] as Interceptable ) [ Interceptor ]
45
46
) {
46
- return
47
+ throw new Error (
48
+ `Element ${ element . tagName } does not implement "${ String ( propName ) } ".` ,
49
+ )
47
50
}
48
51
49
52
function intercept (
Original file line number Diff line number Diff line change @@ -57,7 +57,9 @@ function sanitizeValue(
57
57
return String ( v )
58
58
}
59
59
60
- export function prepareValueInterceptor ( element : HTMLInputElement ) {
60
+ export function prepareValueInterceptor (
61
+ element : HTMLInputElement | HTMLTextAreaElement ,
62
+ ) {
61
63
prepareInterceptor ( element , 'value' , valueInterceptor )
62
64
}
63
65
You can’t perform that action at this time.
0 commit comments