@@ -95,6 +95,56 @@ describe('extending AutoControlledComponent', () => {
95
95
wrapper
96
96
. should . have . state ( randomProp , props [ randomProp ] )
97
97
} )
98
+
99
+ it ( 'sets state for props passed as undefined by the parent' , ( ) => {
100
+ consoleUtil . disableOnce ( )
101
+
102
+ const props = makeProps ( )
103
+ const autoControlledProps = _ . keys ( props )
104
+
105
+ const randomProp = _ . sample ( autoControlledProps )
106
+ const randomValue = faker . hacker . phrase ( )
107
+
108
+ props [ randomProp ] = undefined
109
+
110
+ TestClass = createTestClass ( { autoControlledProps, state : { } } )
111
+ const wrapper = shallow ( < TestClass { ...props } /> )
112
+
113
+ wrapper
114
+ . instance ( )
115
+ . trySetState ( { [ randomProp ] : randomValue } )
116
+
117
+ // not updated
118
+ wrapper
119
+ . should . have . state ( randomProp , randomValue )
120
+ } )
121
+
122
+ it ( 'does not set state for props passed as null by the parent' , ( ) => {
123
+ consoleUtil . disableOnce ( )
124
+
125
+ const props = makeProps ( )
126
+ const autoControlledProps = _ . keys ( props )
127
+
128
+ const randomProp = _ . sample ( autoControlledProps )
129
+ const randomValue = faker . hacker . phrase ( )
130
+
131
+ props [ randomProp ] = null
132
+
133
+ TestClass = createTestClass ( { autoControlledProps, state : { } } )
134
+ const wrapper = shallow ( < TestClass { ...props } /> )
135
+
136
+ wrapper
137
+ . instance ( )
138
+ . trySetState ( { [ randomProp ] : randomValue } )
139
+
140
+ // not updated
141
+ wrapper
142
+ . should . not . have . state ( randomProp , randomValue )
143
+
144
+ // is original value
145
+ wrapper
146
+ . should . have . state ( randomProp , props [ randomProp ] )
147
+ } )
98
148
} )
99
149
100
150
describe ( 'initial state' , ( ) => {
@@ -244,5 +294,41 @@ describe('extending AutoControlledComponent', () => {
244
294
wrapper
245
295
. should . not . have . state ( randomDefaultProp , randomValue )
246
296
} )
297
+
298
+ it ( 'sets state for props passed as undefined by the parent' , ( ) => {
299
+ consoleUtil . disableOnce ( )
300
+
301
+ const props = makeProps ( )
302
+ const autoControlledProps = _ . keys ( props )
303
+
304
+ const randomProp = _ . sample ( autoControlledProps )
305
+
306
+ TestClass = createTestClass ( { autoControlledProps, state : { } } )
307
+ const wrapper = shallow ( < TestClass { ...props } /> )
308
+
309
+ wrapper
310
+ . setProps ( { [ randomProp ] : undefined } )
311
+
312
+ wrapper
313
+ . should . have . state ( randomProp , props [ randomProp ] )
314
+ } )
315
+
316
+ it ( 'does not set state for props passed as null by the parent' , ( ) => {
317
+ consoleUtil . disableOnce ( )
318
+
319
+ const props = makeProps ( )
320
+ const autoControlledProps = _ . keys ( props )
321
+
322
+ const randomProp = _ . sample ( autoControlledProps )
323
+
324
+ TestClass = createTestClass ( { autoControlledProps, state : { } } )
325
+ const wrapper = shallow ( < TestClass { ...props } /> )
326
+
327
+ wrapper
328
+ . setProps ( { [ randomProp ] : null } )
329
+
330
+ wrapper
331
+ . should . have . state ( randomProp , null )
332
+ } )
247
333
} )
248
334
} )
0 commit comments