Completed
Branch master (6959b7)
by Pieter Epeüs
22:59 queued 19:07
created

tests/unit/error.spec.js   A

Complexity

Total Complexity 3
Complexity/F 1

Size

Lines of Code 49
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 35
dl 0
loc 49
rs 10
c 0
b 0
f 0
mnd 0
bc 0
fnc 3
bpm 0
cpm 1
noi 2
1
import Gate from '../../src/LogicGates.mjs';
2
import InvalidInputError from '../../src/InvalidInputError';
3
4
const ErrorTestCases = [
5
    {
6
        description: 'test inputs with a null value',
7
        inputs: null,
8
        expectedError: 'inputs isnt a array of booleans',
9
    },
10
    {
11
        description: 'test inputs with a string',
12
        inputs: 'not ok',
13
        expectedError: 'inputs isnt a array of booleans',
14
    },
15
    {
16
        description: 'test inputs with a string',
17
        inputs: [true, 42],
18
        expectedError: 'inputs isnt a array of booleans',
19
    },
20
    {
21
        description: 'test inputs with a string',
22
        inputs: [1],
23
        expectedError: 'inputs isnt a array of booleans',
24
    },
25
    {
26
        description: 'test inputs with a string',
27
        inputs: [0],
28
        expectedError: 'inputs isnt a array of booleans',
29
    },
30
    {
31
        description: 'test inputs with a string',
32
        inputs: [null],
33
        expectedError: 'inputs isnt a array of booleans',
34
    },
35
];
36
37
describe.each(ErrorTestCases)(
38
    'Test totalTrueInputs helper exception test',
39
    ({ description, inputs, expectedError }) => {
40
        it(description, () => {
41
            function testWrongInput() {
42
                Gate.create(inputs);
43
            }
44
45
            expect(testWrongInput).toThrowError(new Error(expectedError));
46
            expect(testWrongInput).toThrowError(InvalidInputError);
47
        });
48
    }
49
);
50