Passed
Push — main ( e27340...4f7116 )
by Pieter Epeüs
05:55 queued 02:22
created

src/__tests__/timeout-error.unit.js   A

Complexity

Total Complexity 3
Complexity/F 1

Size

Lines of Code 48
Function Count 3

Duplication

Duplicated Lines 48
Ratio 100 %

Importance

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

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