Skip to content

Commit

Permalink
Add some tests to optionals-test
Browse files Browse the repository at this point in the history
  • Loading branch information
tresabhi committed Oct 5, 2024
1 parent 0b7ed9f commit b876c8f
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion integration/proto2/proto2-optionals-test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OptionalsTest } from "./simple";
import { OptionalsTest, OptionalsTest_TranslationsEntry } from "./simple";

describe("proto2-optionals", () => {
it("it compiles", () => {
Expand All @@ -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: "" });
});
});

0 comments on commit b876c8f

Please sign in to comment.