Skip to content

Commit d5c25f0

Browse files
committed
test(utils): add tests for getProp
1 parent b365172 commit d5c25f0

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

tests/utils.test.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { getProp, setProp } from '../src/utils'
22

33
describe('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)

0 commit comments

Comments
 (0)