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

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

Complexity

Total Complexity 3
Complexity/F 1

Size

Lines of Code 37
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 26
mnd 0
bc 0
fnc 3
dl 0
loc 37
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0
1
import { expect, describe, it } from '@jest/globals';
2
import Obj from '../objects.js';
3
4
describe('Object test', () => {
5
    const CountrySchema = {
6
        name: String,
7
        code: String,
8
        active: Boolean,
9
    };
10
11
    const addressSchema = {
12
        street: String,
13
        number: 'number',
14
        postalCode: String,
15
        city: String,
16
        country: CountrySchema,
17
    };
18
19
    //  deepcode ignore ExpectsArray: False error, it should allow an object
20
    const Address = Obj({ schema: addressSchema });
21
22
    it('It should throw an exception', () => {
23
        expect(() => {
24
            Address.create({
25
                street: 'Abc',
26
                number: 42,
27
                postalCode: '1234AB',
28
                city: 'Example',
29
                country: {
30
                    name: 'Germany',
31
                    code: 'DE',
32
                    active: 'true',
33
                },
34
            });
35
        }).toThrowError('The field country.active should be a Boolean');
36
    });
37
});
38