Passed
Pull Request — master (#158)
by Pieter Epeüs
02:57
created

src/__tests__/validate-sub-objects.spec.js   A

Complexity

Total Complexity 3
Complexity/F 1

Size

Lines of Code 39
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 28
mnd 0
bc 0
fnc 3
dl 0
loc 39
rs 10
bpm 0
cpm 1
noi 5
c 0
b 0
f 0
1
/* eslint-disable max-statements */
2
/* eslint-disable no-new */
3
import { expect, describe, it } from '@jest/globals';
4
import Obj from '../objects.js';
5
import test1Schema from '../schemas/test1.js';
0 ignored issues
show
Unused Code introduced by
'test1Schema' is defined but never used.
Loading history...
6
import Test2 from '../schemas/test2.js';
0 ignored issues
show
Unused Code introduced by
'Test2' is defined but never used.
Loading history...
7
8
describe('Object test', () => {
9
    const CountrySchema = {
10
        name: String,
11
        code: String,
12
        active: Boolean
0 ignored issues
show
introduced by
Insert ,
Loading history...
13
    };
14
15
    const addressSchema = {
16
        street: String,
17
        number: 'number',
18
        postalCode: String,
19
        city: String,
20
        country: CountrySchema
0 ignored issues
show
introduced by
Insert ,
Loading history...
21
    };
22
23
    //  deepcode ignore ExpectsArray: False error, it should allow an object
24
    const Address = Obj({ schema: addressSchema });
25
26
    it('It should throw an exception', () => {
27
        expect(() => {
28
            Address.create({
29
                street: 'Abc',
30
                number: 42,
31
                postalCode: '1234AB',
32
                city: 'Example',
33
                country: {
34
                    name: 'Germany',
35
                    code: 'DE',
36
                    active: 'true'
0 ignored issues
show
introduced by
Insert ,
Loading history...
37
                },
38
            });
39
        }).toThrowError('The field country.active should be a Boolean');
40
    });
41
});
42