Skip to content

Commit d67bbbe

Browse files
committed
#233 Create tests for #233
1 parent dff2aff commit d67bbbe

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

test/functional/serialization-deserialization.spec.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,46 @@ describe("serialization and deserialization objects", () => {
107107
// (<any>result).extra.should.be.undefined;
108108
});
109109

110-
});
110+
111+
it("should not overwrite non writable properties on deserialize", () => {
112+
class TestObject {
113+
get getterOnlyProp(): string {
114+
return "I cannot write!";
115+
}
116+
117+
normalProp: string = "Hello!";
118+
}
119+
120+
const payload = {
121+
getterOnlyProp: "I CAN write!",
122+
normalProp: "Goodbye!"
123+
};
124+
125+
const result = deserialize(TestObject, JSON.stringify(payload));
126+
127+
result.getterOnlyProp.should.be.eql("I cannot write!");
128+
result.normalProp.should.be.eql("Goodbye!");
129+
130+
});
131+
132+
it("should overwrite default properties defined in prototype", () => {
133+
class TestObject {
134+
normalProp: string = "Hello!";
135+
prototypedProp: string;
136+
}
137+
138+
TestObject.prototype.prototypedProp = "I'm a BUG!";
139+
140+
141+
const payload = {
142+
normalProp: "Goodbye!",
143+
prototypedProp: "Goodbye!"
144+
};
145+
146+
const result = deserialize(TestObject, JSON.stringify(payload));
147+
148+
result.normalProp.should.be.eql("Goodbye!");
149+
result.prototypedProp.should.be.eql("Goodbye!");
150+
});
151+
152+
});

0 commit comments

Comments
 (0)