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

Complexity

Total Complexity 3
Complexity/F 1

Size

Lines of Code 47
Function Count 3

Duplication

Duplicated Lines 47
Ratio 100 %

Importance

Changes 0
Metric Value
wmc 3
eloc 37
mnd 0
bc 0
fnc 3
dl 47
loc 47
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1 View Code Duplication
import { expect, describe, it } from '@jest/globals';
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
2
import { ServerError } from '../index.js';
3
4
describe('Server Error test', () => {
5
    it('It should create a server error', () => {
6
        const error = new ServerError({
7
            value: 'test',
8
            type: String,
9
            message: 'Example text',
10
        });
11
12
        expect(error instanceof ServerError).toEqual(true);
13
        expect(error instanceof Error).toEqual(true);
14
        expect(error.name).toEqual('ServerError');
15
        expect(error.message).toEqual('Example text');
16
        expect(error.value).toEqual('test');
17
        expect(error.status).toEqual(500);
18
        expect(error.type).toEqual(String);
19
        expect(error.date.constructor).toEqual(Date);
20
        expect(error.stack.includes('ServerError: Example text')).toEqual(true);
21
    });
22
23
    it('It should handle invalid error values', () => {
24
        const error = new ServerError({
25
            value: 'test',
26
            type: 'string',
27
            message: 'Example text',
28
        });
29
30
        expect(error instanceof ServerError).toEqual(true);
31
        expect(error instanceof Error).toEqual(true);
32
        expect(error.name).toEqual('ServerError');
33
        expect(error.message).toEqual('Invalid error');
34
        expect(error.value.errors[0][0]).toEqual('type?');
35
        expect(error.value.values.message).toEqual('Invalid error');
36
        expect(error.value.values.name).toEqual('ServerError');
37
        expect(error.value.values.status).toEqual(500);
38
        expect(error.value.values.type).toEqual(Error);
39
        expect(error.value.values.value).toEqual('test');
40
        expect(error.status).toEqual(500);
41
        expect(error.type).toEqual(Error);
42
        expect(error.date.constructor).toEqual(Date);
43
        expect(error.stack.includes('ServerError: Invalid error')).toEqual(
44
            true
45
        );
46
    });
47
});
48