Skip to content
This repository was archived by the owner on May 4, 2023. It is now read-only.

Commit cfeb790

Browse files
committed
Add more tests
1 parent bfdcdac commit cfeb790

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

src/test/JsogSpec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { ListItem } from './support/ListItem';
2+
import { WithType } from './support/WithType';
23
import { SpecReporter } from 'jasmine-spec-reporter';
34
// Module
45
import { JsonTypescriptService } from './../main/service/JsonTypescriptService';
56
import { Logger } from './../main/log/Logger';
67

78
// Moment
89
import * as moment from 'moment';
10+
import { Parent } from './support/Parent';
911

1012
// Setup...
1113
const log = Logger.getInstance();
@@ -87,3 +89,29 @@ describe('Deserialize null values', () => {
8789
expect(deserialized.lorem).toBeNull();
8890
});
8991
});
92+
93+
describe('Deserializing Model objects', () => {
94+
const parent: any = {
95+
child: {
96+
name: 'Kind',
97+
},
98+
};
99+
100+
const deserialized = jsog.deserializeObject(parent, Parent);
101+
102+
it('should instantiate child', () => {
103+
expect(deserialized.child.getName()).toBeDefined();
104+
});
105+
});
106+
107+
describe('Deserializing Annotated String Types', () => {
108+
const withType: WithType = {
109+
dtype: 'one',
110+
};
111+
112+
const deserialized = jsog.deserializeObject(withType, WithType);
113+
114+
it('should work', () => {
115+
expect(deserialized).toEqual(withType);
116+
});
117+
});

src/test/support/Child.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export class Child {
2+
public name: string;
3+
4+
public getName(): string {
5+
return this.name;
6+
}
7+
}

src/test/support/Parent.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Child } from './Child';
2+
import { JsonProperty } from '../../main/decorators/JsonProperty';
3+
4+
export class Parent {
5+
6+
@JsonProperty()
7+
public child: Child;
8+
9+
constructor(data?: Parent) {
10+
11+
if (!data) {
12+
return;
13+
}
14+
}
15+
}

src/test/support/WithType.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { JsonProperty } from '../../main/decorators/JsonProperty';
2+
3+
type StringType = 'one' | 'other';
4+
5+
export class WithType {
6+
@JsonProperty()
7+
public dtype: StringType;
8+
}

0 commit comments

Comments
 (0)