Passed
Pull Request — master (#35)
by Pieter Epeüs
01:40
created

test/getByKey.js   A

Complexity

Total Complexity 2
Complexity/F 1

Size

Lines of Code 37
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 27
mnd 0
bc 0
fnc 2
dl 0
loc 37
rs 10
bpm 0
cpm 1
noi 1
c 0
b 0
f 0
1
import { Arr } from '../src/helpers';
2
3
const getTestCases = [
4
    {
5
        description: 'Key is missing, no defaultValue provided',
6
        arr: {},
7
        key: 'pizza',
8
        expectedValue: undefined,
9
    },
10
    {
11
        description: 'Key is missing, a defaultValue is provided',
12
        arr: {},
13
        key: 'pizza',
14
        defaultValue: 'margherita',
15
        expectedValue: 'margherita',
16
    },
17
    {
18
        description: 'Nested key',
19
        arr: {
20
            turtles: ['Donatello', 'Michelangelo', 'Raphael', 'Leonardo'],
21
            food: ['Pizza'],
22
            mice: ['Splinter'],
23
        },
24
        key: 'turtles.0',
25
        expectedValue: 'Donatello',
26
    },
27
];
28
29
describe.each(getTestCases)(
30
    'Test Arr.Get',
31
    ({ description, arr, key, defaultValue, expectedValue }) => {
32
        it(description, () => {
33
            const a = new Arr(arr);
34
            expect(a.getByKey(key, defaultValue)).toEqual(expectedValue);
35
        });
36
    }
37
);
38