src/__tests__/error-status.unit.js   A
last analyzed

Complexity

Total Complexity 2
Complexity/F 1

Size

Lines of Code 29
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 20
mnd 0
bc 0
fnc 2
dl 0
loc 29
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0
1
import { expect, describe, it } from '@jest/globals';
2
import getStatusByError from '../error-status.js';
3
4
const TestCases = [
5
    {
6
        description: 'A normal error should return status 500',
7
        error: new Error('test'),
8
        expectedResult: 500,
9
    },
10
    {
11
        description: 'A type error should return status 422',
12
        error: new TypeError('test'),
13
        expectedResult: 422,
14
    },
15
    {
16
        description: 'A range error should return status 404',
17
        error: new RangeError('test'),
18
        expectedResult: 404,
19
    },
20
];
21
22
describe.each(TestCases)(
23
    'Error status entity',
24
    ({ description, error, expectedResult }) => {
25
        it(description, () => {
26
            expect(getStatusByError(error)).toEqual(expectedResult);
27
        });
28
    }
29
);
30