File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { dispatchUIEvent } from '../event'
22import { Config } from '../setup'
3+ import { isElementType } from '../utils'
34import { prepareSelectionInterceptor } from './selection'
45import { prepareRangeTextInterceptor } from './setRangeText'
56import {
@@ -24,7 +25,7 @@ export function prepareDocument(document: Document) {
2425 document . addEventListener (
2526 'focus' ,
2627 e => {
27- const el = e . target as Node
28+ const el = e . target as Element
2829
2930 prepareElement ( el )
3031 } ,
@@ -62,12 +63,12 @@ export function prepareDocument(document: Document) {
6263 document [ isPrepared ] = isPrepared
6364}
6465
65- function prepareElement ( el : Node | HTMLInputElement ) {
66+ function prepareElement ( el : Element ) {
6667 if ( el [ isPrepared ] ) {
6768 return
6869 }
6970
70- if ( 'value' in el ) {
71+ if ( isElementType ( el , [ 'input' , 'textarea' ] ) ) {
7172 prepareValueInterceptor ( el )
7273 prepareSelectionInterceptor ( el )
7374 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]
1010type ImplReturn < Prop > = Prop extends anyFunc ? Parameters < Prop > : Prop
1111
1212export function prepareInterceptor <
13- ElementType extends Node ,
13+ ElementType extends Element ,
1414 PropName extends keyof ElementType ,
1515> (
1616 element : ElementType ,
@@ -39,11 +39,14 @@ export function prepareInterceptor<
3939
4040 const target = prototypeDescriptor ?. set ? 'set' : 'value'
4141
42+ /* istanbul ignore if */
4243 if (
4344 typeof prototypeDescriptor ?. [ target ] !== 'function' ||
4445 ( prototypeDescriptor [ target ] as Interceptable ) [ Interceptor ]
4546 ) {
46- return
47+ throw new Error (
48+ `Element ${ element . tagName } does not implement "${ String ( propName ) } ".` ,
49+ )
4750 }
4851
4952 function intercept (
Original file line number Diff line number Diff line change @@ -57,7 +57,9 @@ function sanitizeValue(
5757 return String ( v )
5858}
5959
60- export function prepareValueInterceptor ( element : HTMLInputElement ) {
60+ export function prepareValueInterceptor (
61+ element : HTMLInputElement | HTMLTextAreaElement ,
62+ ) {
6163 prepareInterceptor ( element , 'value' , valueInterceptor )
6264}
6365
You can’t perform that action at this time.
0 commit comments