File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -112,7 +112,11 @@ export const NestedApi = ({ database }: { database: InternalDatabase }) => {
112112 }
113113 let nested : PossiblyNestedValue = toNested ( relevantKeyValues ) ;
114114 for ( const k of splitKey ( joinedKey ) ) {
115- nested = ( nested as NestedValue ) [ k ] ;
115+ try {
116+ nested = ( nested as NestedValue ) [ k ] ;
117+ } catch {
118+ return undefined ;
119+ }
116120 }
117121 return nested ;
118122 } ;
Original file line number Diff line number Diff line change @@ -180,6 +180,15 @@ describe("Nested Database", () => {
180180 expect ( actualAB ) . to . equal ( 1 ) ;
181181 } ) ;
182182
183+
184+ it ( "get an inexisting nested key" , async ( ) => {
185+ await db . put ( "b/c" , "test" ) ;
186+ await db . del ( "b/c" ) ;
187+
188+ const actual = await db . get ( "b/c" ) ;
189+ expect ( actual ) . to . be . undefined ( ) ;
190+ } ) ;
191+
183192 it ( "remove a nested value" , async ( ) => {
184193 await db . put ( [ "a/b" ] , 1 ) ;
185194 await db . put ( "a/c" , 2 ) ;
You can’t perform that action at this time.
0 commit comments