Completed
Push — master ( 64f3a1...18f77b )
by Pieter Epeüs
23s queued 11s
created

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

Complexity

Total Complexity 6
Complexity/F 1

Size

Lines of Code 54
Function Count 6

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 39
mnd 0
bc 0
fnc 6
dl 0
loc 54
rs 10
bpm 0
cpm 1
noi 2
c 0
b 0
f 0
1
/* eslint-disable no-new */
2
import Obj from '../objects';
3
4
describe('Object test', () => {
5
    const addressSchema = {
6
        street: String,
7
        number: 'number',
8
        postalCode: String,
9
        city: String,
10
        country: String,
11
    };
12
13
    const Address = Obj({ schema: addressSchema });
14
15
    it('It should validate the input and set the original object', () => {
16
        const myAddress = new Address({
17
            street: 'Abc',
18
            number: 42,
19
            postalCode: '1234AB',
20
            city: 'Example',
21
            country: 'The Netherlands',
22
        });
23
24
        expect(myAddress.original).toEqual({
25
            street: 'Abc',
26
            number: 42,
27
            postalCode: '1234AB',
28
            city: 'Example',
29
            country: 'The Netherlands',
30
        });
31
    });
32
33
    it('It should throw an exception', () => {
34
        expect(() => {
35
            new Address({
0 ignored issues
show
Unused Code Best Practice introduced by
The object created with new Address({IdentifierN...ode(The Netherlands))}) is not used but discarded. Consider invoking another function instead of a constructor if you are doing this purely for side effects.
Loading history...
36
                street: 'Abc',
37
                number: 'xyz',
38
                postalCode: '1234AB',
39
                city: 'Example',
40
                country: 'The Netherlands',
41
            });
42
        }).toThrowError('The field number should be a number');
43
    });
44
45
    it('It should throw an exception', () => {
46
        expect(() => {
47
            new Address({
0 ignored issues
show
Unused Code Best Practice introduced by
The object created with new Address({IdentifierN...LiteralNode(Example))}) is not used but discarded. Consider invoking another function instead of a constructor if you are doing this purely for side effects.
Loading history...
48
                street: 'Abc',
49
                number: 42,
50
                postalCode: '1234AB',
51
                city: 'Example',
52
            });
53
        }).toThrowError('The field country should be a String');
54
    });
55
});
56