diff --git a/integration/proto2/proto2-optionals-test.ts b/integration/proto2/proto2-optionals-test.ts index bdea35217..db578ba65 100644 --- a/integration/proto2/proto2-optionals-test.ts +++ b/integration/proto2/proto2-optionals-test.ts @@ -1,4 +1,4 @@ -import { OptionalsTest } from "./simple"; +import { OptionalsTest, OptionalsTest_TranslationsEntry } from "./simple"; describe("proto2-optionals", () => { it("it compiles", () => { @@ -13,4 +13,21 @@ describe("proto2-optionals", () => { expect(decoded).toEqual(message); }); + + it("throws an error if fromJSON is called without providing all required fields", () => { + expect(() => { + OptionalsTest.fromJSON({}); + }).toThrow("Required field OptionalsTest.reqId is not set"); + }); + + it("does not throw an error when using fromPartial and assigns the correct default value", () => { + const message = OptionalsTest.fromPartial({}); + expect(message.reqId).toBe(0); + expect(message.reqDefvalId).toBe(100); + }); + + it("assigns key-value pairs a defined default value even though technically they are optional", () => { + const message = OptionalsTest_TranslationsEntry.create(); + expect(message).toEqual({ key: "", value: "" }); + }); });