-
Notifications
You must be signed in to change notification settings - Fork 510
/
Copy pathinheritence.spec.ts
42 lines (36 loc) · 1.21 KB
/
inheritence.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import 'reflect-metadata';
import { plainToInstance, Transform, Type } from '../../src/index';
import { defaultMetadataStorage } from '../../src/storage';
describe('inheritence', () => {
it('decorators should work inside a base class', () => {
defaultMetadataStorage.clear();
class Contact {
@Transform(({ value }) => value.toUpperCase())
name: string;
@Type(() => Date)
birthDate: Date;
}
class User extends Contact {
@Type(() => Number)
id: number;
email: string;
}
class Student extends User {
@Transform(({ value }) => value.toUpperCase())
university: string;
}
const plainStudent = {
name: 'Johny Cage',
university: 'mit',
birthDate: new Date(1967, 2, 1).toDateString(),
id: 100,
email: 'johnny.cage@gmail.com',
};
const classedStudent = plainToInstance(Student, plainStudent);
expect(classedStudent.name).toEqual('JOHNY CAGE');
expect(classedStudent.university).toEqual('MIT');
expect(classedStudent.birthDate.getTime()).toEqual(new Date(1967, 2, 1).getTime());
expect(classedStudent.id).toEqual(plainStudent.id);
expect(classedStudent.email).toEqual(plainStudent.email);
});
});