File tree Expand file tree Collapse file tree 1 file changed +55
-0
lines changed Expand file tree Collapse file tree 1 file changed +55
-0
lines changed Original file line number Diff line number Diff line change 11import { getProp , setProp } from '../src/utils'
22
33describe ( 'Utilities' , ( ) => {
4+ /**
5+ * Tests of `getProp`
6+ * Based on tests from https://github.com/dy/dotprop (MIT)
7+ */
8+
49 test ( '[getProp]: Get property defined by dot notation in string.' , ( ) => {
510 const holder = {
611 a : {
@@ -15,6 +20,56 @@ describe('Utilities', () => {
1520 expect ( result ) . toBe ( 1 )
1621 } )
1722
23+ test ( '[getProp]: Get property defined by array-type keys.' , ( ) => {
24+ const holder = {
25+ a : {
26+ b : {
27+ c : 1
28+ }
29+ }
30+ }
31+
32+ const result = getProp ( holder , [ 'a' , 'b' , 'c' ] )
33+
34+ expect ( result ) . toBe ( 1 )
35+ } )
36+
37+ test ( '[getProp]: Get property defined by simple string.' , ( ) => {
38+ const holder = {
39+ a : {
40+ b : {
41+ c : 1
42+ }
43+ }
44+ }
45+
46+ const result = getProp ( holder , 'a' )
47+
48+ expect ( result ) . toBe ( holder . a )
49+ } )
50+
51+ test ( '[getProp]: Get holder when propName is not defined.' , ( ) => {
52+ const holder = {
53+ a : {
54+ b : {
55+ c : 1
56+ }
57+ }
58+ }
59+
60+ // @ts -ignore
61+ const result = getProp ( holder )
62+
63+ expect ( result ) . toBe ( holder )
64+ } )
65+
66+ test ( '[getProp]: Get empty object when holder is not defined.' , ( ) => {
67+ // @ts -ignore
68+ const result = getProp ( )
69+
70+ expect ( result ) . toStrictEqual ( { } )
71+ } )
72+
1873 /**
1974 * Tests of `setProp`
2075 * Based on tests from https://github.com/lukeed/dset (MIT)
You can’t perform that action at this time.
0 commit comments