@@ -21,15 +21,23 @@ function waitFrames<T>({
21
21
22
22
if ( ! isWin ) {
23
23
const isJquery = Cypress . dom . isJquery ( subject )
24
- if ( ! isJquery ) { throw new Error ( targetErr ) }
24
+ if ( ! isJquery ) {
25
+ throw new Error ( targetErr )
26
+ }
25
27
26
28
target = ( subject as JQuery < HTMLElement | SVGElement > ) [ '0' ]
27
29
}
28
30
29
- if ( ! target ) { throw new Error ( targetErr ) }
30
- if ( ! Array . isArray ( property ) && typeof property !== 'string' ) { throw new Error ( propsErr ) }
31
+ if ( ! target ) {
32
+ throw new Error ( targetErr )
33
+ }
34
+ if ( ! Array . isArray ( property ) && typeof property !== 'string' ) {
35
+ throw new Error ( propsErr )
36
+ }
31
37
32
- if ( typeof property === 'string' ) { property = [ property ] }
38
+ if ( typeof property === 'string' ) {
39
+ property = [ property ]
40
+ }
33
41
34
42
return await Cypress . Promise . all (
35
43
property . map ( ( prop ) =>
@@ -54,40 +62,36 @@ function getValue<T>({ isWin, cyWin, target, prop }: GetValueOptions<T>): Primit
54
62
55
63
const emptyValue = Symbol ( '' )
56
64
65
+ type Key = keyof typeof target
66
+
57
67
if ( typeof prop === 'string' && prop . includes ( '.' ) ) {
58
- let objValue : symbol | Primitive = emptyValue
68
+ let objValue : Primitive | symbol = emptyValue
59
69
60
70
const [ objOrMethod , _prop ] = prop . split ( '.' )
61
71
62
- if ( typeof target [ objOrMethod as keyof typeof target ] === 'function' ) {
63
- objValue = (
64
- ( target as HTMLElement ) [ objOrMethod as keyof HTMLElement ] as CallableFunction
65
- ) ?.( ) ?. [ _prop ]
72
+ if ( typeof target [ objOrMethod as Key ] === 'function' ) {
73
+ objValue = ( target [ objOrMethod as Key ] as CallableFunction ) ( ) ?. [ _prop ]
66
74
}
67
75
68
- if ( typeof target [ objOrMethod as keyof typeof target ] === 'object' ) {
69
- objValue = (
70
- ( target as HTMLElement ) [ objOrMethod as keyof HTMLElement ] as Record < string , Primitive >
71
- ) ?. [ _prop ]
76
+ if ( typeof target [ objOrMethod as Key ] === 'object' ) {
77
+ objValue = ( target [ objOrMethod as Key ] as Record < string , any > ) ?. [ _prop ]
72
78
}
73
79
74
- if ( objValue !== emptyValue ) { return objValue as Primitive }
80
+ if ( objValue !== emptyValue && isPrimitive ( objValue ) ) { return objValue as Primitive }
75
81
76
82
throw new Error (
77
- `${ ERR } Invalid or unsupported ${ isWin ? 'window' : '' } property: ${ prop as string } `
83
+ `${ ERR } Invalid or unsupported ${ isWin ? 'window' : '' } property: ${ prop as Key } `
78
84
)
79
85
}
80
86
81
- if ( prop in target && isPrimitive ( target [ prop as keyof typeof target ] ) ) {
82
- return target [ prop as keyof typeof target ] as Primitive
83
- }
87
+ if ( prop in target && isPrimitive ( target [ prop as Key ] ) ) { return target [ prop as Key ] as Primitive }
84
88
85
- if ( isWin ) { throw new Error ( `${ ERR } Invalid window property: ${ prop as string } ` ) }
89
+ if ( isWin ) { throw new Error ( `${ ERR } Invalid window property: ${ prop as Key } ` ) }
86
90
87
91
if ( typeof prop === 'string' && prop . startsWith ( '--' ) ) { return getCSS ( ) }
88
92
89
93
if ( ! ( prop in cyWin . getComputedStyle ( target as HTMLElement ) ) ) {
90
- throw new Error ( `${ ERR } Invalid element DOM/CSS property: ${ prop as string } ` )
94
+ throw new Error ( `${ ERR } Invalid element DOM/CSS property: ${ prop as Key } ` )
91
95
}
92
96
93
97
return getCSS ( )
0 commit comments