@@ -45,6 +45,11 @@ describe('ComponentFactoryNgElementStrategy', () => {
45
45
beforeEach ( ( ) => {
46
46
// Set up an initial value to make sure it is passed to the component
47
47
strategy . setInputValue ( 'fooFoo' , 'fooFoo-1' ) ;
48
+ strategy . setInputValue ( 'falsyUndefined' , undefined ) ;
49
+ strategy . setInputValue ( 'falsyNull' , null ) ;
50
+ strategy . setInputValue ( 'falsyEmpty' , '' ) ;
51
+ strategy . setInputValue ( 'falsyFalse' , false ) ;
52
+ strategy . setInputValue ( 'falsyZero' , 0 ) ;
48
53
strategy . connect ( document . createElement ( 'div' ) ) ;
49
54
} ) ;
50
55
@@ -73,11 +78,39 @@ describe('ComponentFactoryNgElementStrategy', () => {
73
78
expect ( componentRef . instance . fooFoo ) . toBe ( 'fooFoo-1' ) ;
74
79
} ) ;
75
80
81
+ it ( 'should initialize the component with falsy initial values' , ( ) => {
82
+ expect ( strategy . getInputValue ( 'falsyUndefined' ) ) . toEqual ( undefined ) ;
83
+ expect ( componentRef . instance . falsyUndefined ) . toEqual ( undefined ) ;
84
+ expect ( strategy . getInputValue ( 'falsyNull' ) ) . toEqual ( null ) ;
85
+ expect ( componentRef . instance . falsyNull ) . toEqual ( null ) ;
86
+ expect ( strategy . getInputValue ( 'falsyEmpty' ) ) . toEqual ( '' ) ;
87
+ expect ( componentRef . instance . falsyEmpty ) . toEqual ( '' ) ;
88
+ expect ( strategy . getInputValue ( 'falsyFalse' ) ) . toEqual ( false ) ;
89
+ expect ( componentRef . instance . falsyFalse ) . toEqual ( false ) ;
90
+ expect ( strategy . getInputValue ( 'falsyZero' ) ) . toEqual ( 0 ) ;
91
+ expect ( componentRef . instance . falsyZero ) . toEqual ( 0 ) ;
92
+ } ) ;
93
+
76
94
it ( 'should call ngOnChanges with the change' , ( ) => {
77
- expectSimpleChanges (
78
- componentRef . instance . simpleChanges [ 0 ] ,
79
- { fooFoo : new SimpleChange ( undefined , 'fooFoo-1' , false ) } ) ;
95
+ expectSimpleChanges ( componentRef . instance . simpleChanges [ 0 ] , {
96
+ fooFoo : new SimpleChange ( undefined , 'fooFoo-1' , false ) ,
97
+ falsyNull : new SimpleChange ( undefined , null , false ) ,
98
+ falsyEmpty : new SimpleChange ( undefined , '' , false ) ,
99
+ falsyFalse : new SimpleChange ( undefined , false , false ) ,
100
+ falsyZero : new SimpleChange ( undefined , 0 , false ) ,
101
+ } ) ;
80
102
} ) ;
103
+
104
+ it ( 'should call ngOnChanges with proper firstChange value' , fakeAsync ( ( ) => {
105
+ strategy . setInputValue ( 'falsyUndefined' , 'notanymore' ) ;
106
+ strategy . setInputValue ( 'barBar' , 'barBar-1' ) ;
107
+ tick ( 16 ) ; // scheduler waits 16ms if RAF is unavailable
108
+ ( strategy as any ) . detectChanges ( ) ;
109
+ expectSimpleChanges ( componentRef . instance . simpleChanges [ 1 ] , {
110
+ falsyUndefined : new SimpleChange ( undefined , 'notanymore' , false ) ,
111
+ barBar : new SimpleChange ( undefined , 'barBar-1' , true ) ,
112
+ } ) ;
113
+ } ) ) ;
81
114
} ) ;
82
115
83
116
it ( 'should not call ngOnChanges if not present on the component' , ( ) => {
@@ -234,6 +267,11 @@ export class FakeComponentFactory extends ComponentFactory<any> {
234
267
return [
235
268
{ propName : 'fooFoo' , templateName : 'fooFoo' } ,
236
269
{ propName : 'barBar' , templateName : 'my-bar-bar' } ,
270
+ { propName : 'falsyUndefined' , templateName : 'falsyUndefined' } ,
271
+ { propName : 'falsyNull' , templateName : 'falsyNull' } ,
272
+ { propName : 'falsyEmpty' , templateName : 'falsyEmpty' } ,
273
+ { propName : 'falsyFalse' , templateName : 'falsyFalse' } ,
274
+ { propName : 'falsyZero' , templateName : 'falsyZero' } ,
237
275
] ;
238
276
}
239
277
0 commit comments