@@ -22,47 +22,72 @@ const define = makeRender<any>()
22
22
describe ( 'component props (vapor)' , ( ) => {
23
23
test ( 'stateful' , ( ) => {
24
24
let props : any
25
- // TODO: attrs
25
+ let attrs : any
26
26
27
27
const { render } = define ( {
28
28
props : [ 'fooBar' , 'barBaz' ] ,
29
29
render ( ) {
30
30
const instance = getCurrentInstance ( ) !
31
31
props = instance . props
32
+ attrs = instance . attrs
32
33
} ,
33
34
} )
34
35
35
36
render ( {
36
37
get fooBar ( ) {
37
38
return 1
38
39
} ,
40
+ get bar ( ) {
41
+ return 2
42
+ } ,
39
43
} )
40
44
expect ( props . fooBar ) . toEqual ( 1 )
45
+ expect ( attrs . bar ) . toEqual ( 2 )
41
46
42
47
// test passing kebab-case and resolving to camelCase
43
48
render ( {
44
49
get [ 'foo-bar' ] ( ) {
45
50
return 2
46
51
} ,
52
+ get bar ( ) {
53
+ return 3
54
+ } ,
55
+ get baz ( ) {
56
+ return 4
57
+ } ,
47
58
} )
48
59
expect ( props . fooBar ) . toEqual ( 2 )
60
+ expect ( attrs . bar ) . toEqual ( 3 )
61
+ expect ( attrs . baz ) . toEqual ( 4 )
49
62
50
63
// test updating kebab-case should not delete it (#955)
51
64
render ( {
52
65
get [ 'foo-bar' ] ( ) {
53
66
return 3
54
67
} ,
68
+ get bar ( ) {
69
+ return 3
70
+ } ,
71
+ get baz ( ) {
72
+ return 4
73
+ } ,
55
74
get barBaz ( ) {
56
75
return 5
57
76
} ,
58
77
} )
59
78
expect ( props . fooBar ) . toEqual ( 3 )
60
79
expect ( props . barBaz ) . toEqual ( 5 )
80
+ expect ( attrs . bar ) . toEqual ( 3 )
81
+ expect ( attrs . baz ) . toEqual ( 4 )
61
82
62
- render ( { } )
83
+ render ( {
84
+ get qux ( ) {
85
+ return 5
86
+ } ,
87
+ } )
63
88
expect ( props . fooBar ) . toBeUndefined ( )
64
89
expect ( props . barBaz ) . toBeUndefined ( )
65
- // expect(props .qux).toEqual(5) // TODO: attrs
90
+ expect ( attrs . qux ) . toEqual ( 5 )
66
91
} )
67
92
68
93
test . todo ( 'stateful with setup' , ( ) => {
@@ -71,59 +96,78 @@ describe('component props (vapor)', () => {
71
96
72
97
test ( 'functional with declaration' , ( ) => {
73
98
let props : any
74
- // TODO: attrs
99
+ let attrs : any
75
100
76
101
const { component : Comp , render } = define ( ( _props : any ) => {
77
102
const instance = getCurrentInstance ( ) !
78
103
props = instance . props
104
+ attrs = instance . attrs
79
105
return { }
80
106
} )
81
107
Comp . props = [ 'foo' ]
82
- Comp . render = ( ( ) => { } ) as any
83
108
84
109
render ( {
85
110
get foo ( ) {
86
111
return 1
87
112
} ,
113
+ get bar ( ) {
114
+ return 2
115
+ } ,
88
116
} )
89
117
expect ( props . foo ) . toEqual ( 1 )
118
+ expect ( attrs . bar ) . toEqual ( 2 )
90
119
91
120
render ( {
92
121
get foo ( ) {
93
122
return 2
94
123
} ,
124
+ get bar ( ) {
125
+ return 3
126
+ } ,
127
+ get baz ( ) {
128
+ return 4
129
+ } ,
95
130
} )
96
131
expect ( props . foo ) . toEqual ( 2 )
132
+ expect ( attrs . bar ) . toEqual ( 3 )
133
+ expect ( attrs . baz ) . toEqual ( 4 )
97
134
98
- render ( { } )
135
+ render ( {
136
+ get qux ( ) {
137
+ return 5
138
+ } ,
139
+ } )
99
140
expect ( props . foo ) . toBeUndefined ( )
141
+ expect ( attrs . qux ) . toEqual ( 5 )
100
142
} )
101
143
144
+ // FIXME:
102
145
test ( 'functional without declaration' , ( ) => {
103
146
let props : any
104
- // TODO: attrs
147
+ let attrs : any
105
148
106
- const { component : Comp , render } = define ( ( _props : any ) => {
149
+ const { render } = define ( ( _props : any , { attrs : _attrs } : any ) => {
107
150
const instance = getCurrentInstance ( ) !
108
151
props = instance . props
152
+ attrs = instance . attrs
109
153
return { }
110
154
} )
111
- Comp . props = undefined as any
112
- Comp . render = ( ( ) => { } ) as any
113
155
114
156
render ( {
115
157
get foo ( ) {
116
158
return 1
117
159
} ,
118
160
} )
119
- expect ( props . foo ) . toBeUndefined ( )
161
+ expect ( props . foo ) . toEqual ( 1 )
162
+ expect ( attrs . foo ) . toEqual ( 1 )
120
163
121
164
render ( {
122
165
get foo ( ) {
123
166
return 2
124
167
} ,
125
168
} )
126
- expect ( props . foo ) . toBeUndefined ( )
169
+ expect ( props . foo ) . toEqual ( 2 )
170
+ expect ( attrs . foo ) . toEqual ( 2 )
127
171
} )
128
172
129
173
test ( 'boolean casting' , ( ) => {
@@ -490,8 +534,34 @@ describe('component props (vapor)', () => {
490
534
} )
491
535
492
536
// #5016
493
- test . todo ( 'handling attr with undefined value' , ( ) => {
494
- // TODO: attrs
537
+ test ( 'handling attr with undefined value' , ( ) => {
538
+ const { render, host } = define ( {
539
+ render ( ) {
540
+ const instance = getCurrentInstance ( ) !
541
+ const t0 = template ( '<div></div>' )
542
+ const n0 = t0 ( )
543
+ const n1 = children ( n0 , 0 )
544
+ watchEffect ( ( ) => {
545
+ setText (
546
+ n1 ,
547
+ JSON . stringify ( instance . attrs ) + Object . keys ( instance . attrs ) ,
548
+ )
549
+ } )
550
+ return n0
551
+ } ,
552
+ } )
553
+
554
+ let attrs : any = {
555
+ get foo ( ) {
556
+ return undefined
557
+ } ,
558
+ }
559
+
560
+ render ( attrs )
561
+
562
+ expect ( host . innerHTML ) . toBe (
563
+ `<div>${ JSON . stringify ( attrs ) + Object . keys ( attrs ) } </div>` ,
564
+ )
495
565
} )
496
566
497
567
// #6915
0 commit comments