@@ -34,31 +34,34 @@ describe('getIn', () => {
34
34
) . toThrow ( 'Invalid keyPath: expected Ordered Collection or Array: abc' ) ;
35
35
} ) ;
36
36
37
- it ( 'deep get throws if non-readable path' , ( ) => {
37
+ function withWarnings ( fn ) {
38
38
const realWarn = console . warn ;
39
39
const warnings : Array < any > = [ ] ;
40
40
console . warn = w => warnings . push ( w ) ;
41
-
42
41
try {
43
- const deep = Map ( { key : { regular : "jsobj" } , list : List ( [ Map ( { num : 10 } ) ] ) } ) ;
44
- deep . getIn ( [ "key" , "foo" , "item" ] ) ;
45
- expect ( warnings . length ) . toBe ( 1 ) ;
46
- expect ( warnings [ 0 ] ) . toBe (
47
- 'Invalid keyPath: Value at ["key"] does not have a .get() method: [object Object]' +
48
- '\nThis warning will throw in a future version' ,
49
- ) ;
50
-
51
- warnings . length = 0 ;
52
- deep . getIn ( [ "list" , 0 , "num" , "badKey" ] ) ;
53
- expect ( warnings . length ) . toBe ( 1 ) ;
54
- expect ( warnings [ 0 ] ) . toBe (
55
- 'Invalid keyPath: Value at ["list",0,"num"] does not have a .get() method: 10' +
56
- '\nThis warning will throw in a future version' ,
57
- ) ;
42
+ fn ( warnings ) ;
58
43
} finally {
59
44
console . warn = realWarn ;
60
45
}
61
- } ) ;
46
+ }
47
+
48
+ it ( 'deep get throws if non-readable path' , withWarnings ( warnings => {
49
+ const deep = Map ( { key : { regular : "jsobj" } , list : List ( [ Map ( { num : 10 } ) ] ) } ) ;
50
+ deep . getIn ( [ "key" , "foo" , "item" ] ) ;
51
+ expect ( warnings . length ) . toBe ( 1 ) ;
52
+ expect ( warnings [ 0 ] ) . toBe (
53
+ 'Invalid keyPath: Value at ["key"] does not have a .get() method: [object Object]' +
54
+ '\nThis warning will throw in a future version' ,
55
+ ) ;
56
+
57
+ warnings . length = 0 ;
58
+ deep . getIn ( [ "list" , 0 , "num" , "badKey" ] ) ;
59
+ expect ( warnings . length ) . toBe ( 1 ) ;
60
+ expect ( warnings [ 0 ] ) . toBe (
61
+ 'Invalid keyPath: Value at ["list",0,"num"] does not have a .get() method: 10' +
62
+ '\nThis warning will throw in a future version' ,
63
+ ) ;
64
+ } ) ) ;
62
65
63
66
it ( 'deep get returns not found if path does not match' , ( ) => {
64
67
const m = fromJS ( { a : { b : { c : 10 } } } ) ;
@@ -76,4 +79,12 @@ describe('getIn', () => {
76
79
expect ( m . getIn ( [ 'a' , 'b' , 'd' ] , 123 ) ) . toEqual ( undefined ) ;
77
80
} ) ;
78
81
82
+ it ( 'deep get returns not found if path encounters null or undefined' , withWarnings ( warnings => {
83
+ const m = fromJS ( { a : { b : { c : null , d : undefined } } } ) ;
84
+ expect ( m . getIn ( [ 'a' , 'b' , 'c' , 'x' ] ) ) . toEqual ( undefined ) ;
85
+ expect ( m . getIn ( [ 'a' , 'b' , 'd' , 'x' ] ) ) . toEqual ( undefined ) ;
86
+ expect ( m . getIn ( [ 'a' , 'b' , 'c' , 'x' ] , 123 ) ) . toEqual ( 123 ) ;
87
+ expect ( m . getIn ( [ 'a' , 'b' , 'd' , 'x' ] , 123 ) ) . toEqual ( 123 ) ;
88
+ expect ( warnings . length ) . toBe ( 0 ) ;
89
+ } ) ) ;
79
90
} ) ;
0 commit comments