@@ -18,45 +18,80 @@ afterEach(() => {
18
18
Vue . configureCompat ( { MODE : 3 } )
19
19
} )
20
20
21
- test ( 'COMPONENT_FUNCTIONAL' , async ( ) => {
22
- const func = {
23
- name : 'Func' ,
24
- functional : true ,
25
- props : {
26
- x : String
27
- } ,
28
- inject : [ 'foo' ] ,
29
- render : ( h : any , { data, props, injections, slots } : any ) => {
30
- return h ( 'div' , { id : props . x , class : data . class } , [
31
- h ( 'div' , { class : 'inject' } , injections . foo ) ,
32
- h ( 'div' , { class : 'slot' } , slots ( ) . default )
33
- ] )
21
+ describe ( 'COMPONENT_FUNCTIONAL' , ( ) => {
22
+ test ( 'basic usage' , async ( ) => {
23
+ const func = {
24
+ name : 'Func' ,
25
+ functional : true ,
26
+ props : {
27
+ x : String
28
+ } ,
29
+ inject : [ 'foo' ] ,
30
+ render : ( h : any , { data, props, injections, slots } : any ) => {
31
+ return h ( 'div' , { id : props . x , class : data . class } , [
32
+ h ( 'div' , { class : 'inject' } , injections . foo ) ,
33
+ h ( 'div' , { class : 'slot' } , slots ( ) . default )
34
+ ] )
35
+ }
34
36
}
35
- }
36
37
37
- const vm = new Vue ( {
38
- provide ( ) {
39
- return {
40
- foo : 123
38
+ const vm = new Vue ( {
39
+ provide ( ) {
40
+ return {
41
+ foo : 123
42
+ }
43
+ } ,
44
+ components : {
45
+ func
46
+ } ,
47
+ template : `<func class="foo" x="foo">hello</func>`
48
+ } ) . $mount ( )
49
+
50
+ expect ( vm . $el . id ) . toBe ( 'foo' )
51
+ expect ( vm . $el . className ) . toBe ( 'foo' )
52
+ expect ( vm . $el . querySelector ( '.inject' ) . textContent ) . toBe ( '123' )
53
+ expect ( vm . $el . querySelector ( '.slot' ) . textContent ) . toBe ( 'hello' )
54
+ expect ( vm . $el . outerHTML ) . toMatchInlineSnapshot (
55
+ `"<div id=\\"foo\\" class=\\"foo\\"><div class=\\"inject\\">123</div><div class=\\"slot\\">hello</div></div>"`
56
+ )
57
+
58
+ expect (
59
+ (
60
+ deprecationData [ DeprecationTypes . COMPONENT_FUNCTIONAL ]
61
+ . message as Function
62
+ ) ( func )
63
+ ) . toHaveBeenWarned ( )
64
+ } )
65
+
66
+ test ( 'copies compatConfig option' , ( ) => {
67
+ const func = {
68
+ name : 'Func' ,
69
+ functional : true ,
70
+ compatConfig : {
71
+ ATTR_FALSE_VALUE : 'suppress-warning' as const
72
+ } ,
73
+ render : ( h : any ) => {
74
+ // should not render required: false due to compatConfig
75
+ return h ( 'div' , { 'data-some-attr' : false } )
41
76
}
42
- } ,
43
- components : {
44
- func
45
- } ,
46
- template : `<func class="foo" x="foo">hello</func>`
47
- } ) . $mount ( )
48
-
49
- expect ( vm . $el . id ) . toBe ( 'foo' )
50
- expect ( vm . $el . className ) . toBe ( 'foo' )
51
- expect ( vm . $el . querySelector ( '.inject' ) . textContent ) . toBe ( '123' )
52
- expect ( vm . $el . querySelector ( '.slot' ) . textContent ) . toBe ( 'hello' )
53
- expect ( vm . $el . outerHTML ) . toMatchInlineSnapshot (
54
- `"<div id=\\"foo\\" class=\\"foo\\"><div class=\\"inject\\">123</div><div class=\\"slot\\">hello</div></div>"`
55
- )
56
-
57
- expect (
58
- (
59
- deprecationData [ DeprecationTypes . COMPONENT_FUNCTIONAL ] . message as Function
60
- ) ( func )
61
- ) . toHaveBeenWarned ( )
77
+ }
78
+
79
+ const vm = new Vue ( {
80
+ components : { func } ,
81
+ template : `<func class="foo" x="foo">hello</func>`
82
+ } ) . $mount ( )
83
+
84
+ expect ( vm . $el . outerHTML ) . toMatchInlineSnapshot ( `"<div></div>"` )
85
+ expect (
86
+ (
87
+ deprecationData [ DeprecationTypes . COMPONENT_FUNCTIONAL ]
88
+ . message as Function
89
+ ) ( func )
90
+ ) . toHaveBeenWarned ( )
91
+ expect (
92
+ ( deprecationData [ DeprecationTypes . ATTR_FALSE_VALUE ] . message as Function ) (
93
+ func
94
+ )
95
+ ) . not . toHaveBeenWarned ( )
96
+ } )
62
97
} )
0 commit comments