Total Complexity | 6 |
Complexity/F | 1 |
Lines of Code | 54 |
Function Count | 6 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 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({ |
||
|
|||
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({ |
||
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 |