8000 More tests. · hubcarl/json-typescript-mapper@8152e51 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8152e51

Browse files
Mönnich Daniel, ENT-BD-PDDMönnich Daniel, ENT-BD-PDD
Mönnich Daniel, ENT-BD-PDD
authored and
Mönnich Daniel, ENT-BD-PDD
committed
More tests.
1 parent 959f4af commit 8152e51

File tree

2 files changed

+81
-4
lines changed

2 files changed

+81
-4
lines changed

spec/custom-converter.js

Lines changed: 49 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/custom-converter.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Student {
2424
}
2525

2626

27-
//TODO put in main test file where serialization is tested
27+
//TODO put in main test file where deserialization is tested
2828
describe('custom-converter', function () {
2929

3030
it('should use the custom converter if available for deserialization', function () {
@@ -120,6 +120,36 @@ describe('serialize', function () {
120120
expect(serializedInstance.other.date).to.equal('some-date');
121121
});
122122

123-
//TODO test with Arrays
123+
describe('Arrays', () => {
124+
it('should keep as is if no clazz is specified', function () {
125+
class ClassWithArrayProp {
126+
@JsonProperty('items')
127+
items: Array<Date> = [new Date(), new Date()];
128+
}
129+
const instance = new ClassWithArrayProp();
130+
const serializedInstance = serialize(instance);
131+
expect(serializedInstance.items).to.be.instanceof(Array);
132+
expect(serializedInstance.items.length).to.equal(2);
133+
expect(serializedInstance.items[0]).to.equal(instance.items[0]);
134+
expect(serializedInstance.items[1]).to.equal(instance.items[1]);
135+
});
136+
137+
it('should apply serialize for all array items if clazz is specified', function () {
138+
class OtherClass {
139+
@JsonProperty({name: 'date', customConverter: dateConverter})
140+
date: Date = new Date();
141+
}
142+
class ClassWithArrayProp {
143+
@JsonProperty({name: 'items', clazz: OtherClass})
144+
items: Array<OtherClass> = [new OtherClass(), new OtherClass()];
145+
}
146+
const instance = new ClassWithArrayProp();
147+
const serializedInstance = serialize(instance);
148+
expect(serializedInstance.items).to.be.instanceof(Array);
149+
expect(serializedInstance.items.length).to.equal(2);
150+
expect(serializedInstance.items[0].date).to.equal('some-date');
151+
expect(serializedInstance.items[1].date).to.equal('some-date');
152+
});
153+
});
124154

125155
});

0 commit comments

Comments
 (0)
0