11import { describe , it , expect } from "vitest" ;
22
3- import { equalObjPaths , getValue , setValue , normalizeObjPath } from "./objPath" ;
3+ import {
4+ equalObjPaths ,
5+ getValue ,
6+ setValue ,
7+ normalizeObjPath ,
8+ formatObjPath ,
9+ } from "./objPath" ;
410
511describe ( "Test that getValue()" , ( ) => {
612 it ( "works on 0th level" , ( ) => {
@@ -20,6 +26,12 @@ describe("Test that getValue()", () => {
2026 expect ( getValue ( obj , [ "a" , 2 ] ) ) . toEqual ( 3 ) ;
2127 expect ( getValue ( obj , [ "b" , "c" ] ) ) . toEqual ( "x" ) ;
2228 } ) ;
29+
30+ it ( "ignores missing props" , ( ) => {
31+ const obj = { a : [ 1 , 2 , 3 ] , b : { c : "x" } } ;
32+ expect ( getValue ( obj , [ "c" , 6 , "d" ] ) ) . toBeUndefined ( ) ;
33+ expect ( getValue ( obj , [ "b" , "c" , "d" , "e" ] ) ) . toBeUndefined ( ) ;
34+ } ) ;
2335} ) ;
2436
2537describe ( "Test that setValue()" , ( ) => {
@@ -99,6 +111,16 @@ describe("Test that normalizeObjPath()", () => {
99111 } ) ;
100112} ) ;
101113
114+ describe ( "Test that formatObjPath()" , ( ) => {
115+ it ( "works" , ( ) => {
116+ expect ( formatObjPath ( undefined ) ) . toEqual ( "" ) ;
117+ expect ( formatObjPath ( [ ] ) ) . toEqual ( "" ) ;
118+ expect ( formatObjPath ( [ "a" , 3 , "c" ] ) ) . toEqual ( "a.3.c" ) ;
119+ expect ( formatObjPath ( "a.b.3" ) ) . toEqual ( "a.b.3" ) ;
120+ expect ( formatObjPath ( 6 ) ) . toEqual ( "6" ) ;
121+ } ) ;
122+ } ) ;
123+
102124describe ( "Test that equalObjPaths()" , ( ) => {
103125 it ( "works with equal paths" , ( ) => {
104126 expect ( equalObjPaths ( "a" , "a" ) ) . toBe ( true ) ;
0 commit comments