Passed
Branch feature/first-draft (521840)
by Pieter Epeüs
02:27
created

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

Complexity

Total Complexity 3
Complexity/F 1

Size

Lines of Code 46
Function Count 3

Duplication

Duplicated Lines 46
Ratio 100 %

Importance

Changes 0
Metric Value
wmc 3
eloc 36
mnd 0
bc 0
fnc 3
dl 46
loc 46
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
/** global: describe */
2 View Code Duplication
import makeAppError from '../app-error';
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
3
4
const AppError = makeAppError();
5
6
describe('App Error test', () => {
7
    it('It should create a app error', () => {
8
        const error = new AppError({
9
            value: 'test',
10
            type: String,
11
            message: 'Example text',
12
        });
13
14
        expect(error instanceof AppError).toEqual(true);
15
        expect(error instanceof Error).toEqual(true);
16
        expect(error.name).toEqual('AppError');
17
        expect(error.message).toEqual('Example text');
18
        expect(error.value).toEqual('test');
19
        expect(error.status).toEqual(500);
20
        expect(error.type).toEqual(String);
21
        expect(error.date.constructor).toEqual(Date);
22
        expect(error.stack.includes('AppError: Example text')).toEqual(true);
23
    });
24
25
    it('It should handle invalid error values', () => {
26
        const error = new AppError({
27
            value: 'test',
28
            type: 'string',
29
            message: 'Example text',
30
        });
31
32
        expect(error instanceof AppError).toEqual(true);
33
        expect(error instanceof Error).toEqual(true);
34
        expect(error.name).toEqual('AppError');
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('AppError');
39
        expect(error.value.values.status).toEqual(500);
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('AppError: Invalid error')).toEqual(true);
46
    });
47
});
48