File tree Expand file tree Collapse file tree 3 files changed +35
-10
lines changed Expand file tree Collapse file tree 3 files changed +35
-10
lines changed Original file line number Diff line number Diff line change @@ -10,20 +10,23 @@ export class DOMWrapper<ElementType extends Element> {
10
10
this . element = element
11
11
}
12
12
13
- classes ( className ?: string ) {
13
+ classes ( ) : string [ ]
14
+ classes ( className : string ) : boolean
15
+ classes ( className ?: string ) : string [ ] | boolean {
14
16
const classes = this . element . classList
15
17
16
18
if ( className ) return classes . contains ( className )
17
19
18
20
return Array . from ( classes )
19
21
}
20
22
21
- attributes ( key ?: string ) {
22
- const attributes = this . element . attributes
23
- const attributeMap = { }
24
- for ( let i = 0 ; i < attributes . length ; i ++ ) {
25
- const att = attributes . item ( i )
26
- attributeMap [ att . localName ] = att . value
23
+ attributes ( ) : { [ key : string ] : string }
24
+ attributes ( key : string ) : string
25
+ attributes ( key ?: string ) : { [ key : string ] : string } | string {
26
+ const attributes = Array . from ( this . element . attributes )
27
+ const attributeMap : Record < string , string > = { }
28
+ for ( const attribute of attributes ) {
29
+ attributeMap [ attribute . localName ] = attribute . value
27
30
}
28
31
29
32
return key ? attributeMap [ key ] : attributeMap
Original file line number Diff line number Diff line change @@ -45,16 +45,22 @@ export class VueWrapper<T extends ComponentPublicInstance> {
45
45
return this . componentVM
46
46
}
47
47
48
- props ( selector ?: string ) {
48
+ props ( ) : { [ key : string ] : any }
49
+ props ( selector : string ) : any
50
+ props ( selector ?: string ) : { [ key : string ] : any } | any {
49
51
const props = this . componentVM . $props as { [ key : string ] : any }
50
52
return selector ? props [ selector ] : props
51
53
}
52
54
53
- classes ( className ?: string ) {
55
+ classes ( ) : string [ ]
56
+ classes ( className : string ) : boolean
57
+ classes ( className ?: string ) : string [ ] | boolean {
54
58
return new DOMWrapper ( this . element ) . classes ( className )
55
59
}
56
60
57
- attributes ( key ?: string ) {
61
+ attributes ( ) : { [ key : string ] : string }
62
+ attributes ( key : string ) : string
63
+ attributes ( key ?: string ) : { [ key : string ] : string } | string {
58
64
return new DOMWrapper ( this . element ) . attributes ( key )
59
65
}
60
66
Original file line number Diff line number Diff line change @@ -86,3 +86,19 @@ expectType<SVGLineElement>(line.element)
86
86
// string selector
87
87
byClass = domWrapper . get ( '.todo' )
88
88
expectType < Element > ( byClass . element )
89
+
90
+ // attributes
91
+ expectType < { [ key : string ] : string } > ( wrapper . attributes ( ) )
92
+ expectType < string > ( wrapper . attributes ( 'key' ) )
93
+ expectType < { [ key : string ] : string } > ( domWrapper . attributes ( ) )
94
+ expectType < string > ( domWrapper . attributes ( 'key' ) )
95
+
96
+ // classes
97
+ expectType < Array < string > > ( wrapper . classes ( ) )
98
+ expectType < boolean > ( wrapper . classes ( 'class' ) )
99
+ expectType < Array < string > > ( domWrapper . classes ( ) )
100
+ expectType < boolean > ( domWrapper . classes ( 'class' ) )
101
+
102
+ // props
103
+ expectType < { [ key : string ] : any } > ( wrapper . props ( ) )
104
+ expectType < any > ( wrapper . props ( 'prop' ) )
You can’t perform that action at this time.
0 commit comments