File tree Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -122,6 +122,34 @@ test('setValues/setInitialValues', () => {
122
122
expect ( form . values . aa ) . toBeUndefined ( )
123
123
} )
124
124
125
+ test ( 'setValues with null' , ( ) => {
126
+ const form = attach ( createForm ( ) )
127
+ form . setInitialValues ( {
128
+ 'object-1' : {
129
+ 'array-1' : null ,
130
+ } ,
131
+ 'object-2' : {
132
+ 'array-2' : null ,
133
+ } ,
134
+ } )
135
+ form . setValues ( {
136
+ 'object-1' : {
137
+ 'array-1' : null ,
138
+ } ,
139
+ 'object-2' : {
140
+ 'array-2' : null ,
141
+ } ,
142
+ } )
143
+ expect ( form . values ) . toEqual ( {
144
+ 'object-1' : {
145
+ 'array-1' : null ,
146
+ } ,
147
+ 'object-2' : {
148
+ 'array-2' : null ,
149
+ } ,
150
+ } )
151
+ } )
152
+
125
153
test ( 'observable values/initialValues' , ( ) => {
126
154
const values : any = observable ( {
127
155
aa : 123 ,
Original file line number Diff line number Diff line change 1
1
import { each } from './array'
2
2
import { isEmpty , isValid } from './isEmpty'
3
- import { getType , isArr } from './checkers'
3
+ import { getType , isArr , isPlainObj } from './checkers'
4
4
5
5
const isUnNormalObject = ( value : any ) => {
6
6
if ( value ?. _owner && value ?. $$typeof ) {
@@ -34,7 +34,11 @@ export const defaults = (defaults_: any, targets: any) => {
34
34
) {
35
35
return ! isEmpty ( targets ) ? targets : defaults_
36
36
} else {
37
- const results = isArr ( defaults_ ) ? [ ] : { }
37
+ const results = isArr ( defaults_ )
38
+ ? [ ]
39
+ : isPlainObj ( defaults_ )
40
+ ? { }
41
+ : defaults_
38
42
each ( targets , ( value , key ) => {
39
43
results [ key ] = defaults ( defaults_ [ key ] , value )
40
44
} )
You can’t perform that action at this time.
0 commit comments