File tree Expand file tree Collapse file tree
packages/query-devtools/src/__tests__ Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -539,6 +539,38 @@ describe('Utils tests', () => {
539539 ` )
540540 } )
541541
542+ describe ( 'array nested path' , ( ) => {
543+ it ( 'should delete nested data inside an array correctly' , ( ) => {
544+ const oldData = [
545+ { id : 1 , title : 'first' } ,
546+ { id : 2 , title : 'second' } ,
547+ ]
548+
549+ const newData = deleteNestedDataByPath ( oldData , [ '1' , 'title' ] )
550+
551+ expect ( newData ) . not . toBe ( oldData )
552+ expect ( newData ) . toMatchInlineSnapshot ( `
553+ [
554+ {
555+ "id": 1,
556+ "title": "first",
557+ },
558+ {
559+ "id": 2,
560+ },
561+ ]
562+ ` )
563+ } )
564+ } )
565+
566+ describe ( 'primitive' , ( ) => {
567+ it ( 'should return primitive data as-is when it is not an Object/Array/Map/Set' , ( ) => {
568+ expect ( deleteNestedDataByPath ( 42 , [ 'x' ] ) ) . toBe ( 42 )
569+ expect ( deleteNestedDataByPath ( 'hello' , [ 'x' ] ) ) . toBe ( 'hello' )
570+ expect ( deleteNestedDataByPath ( null , [ 'x' ] ) ) . toBe ( null )
571+ } )
572+ } )
573+
542574 describe ( 'nested data' , ( ) => {
543575 it ( 'should delete nested items correctly' , ( ) => {
544576 /* eslint-disable cspell/spellchecker */
You can’t perform that action at this time.
0 commit comments