| Total Complexity | 2 |
| Complexity/F | 1 |
| Lines of Code | 37 |
| Function Count | 2 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |