Skip to content

Commit 9565c48

Browse files
committed
Combine similar mergeExamples tests using test.each()
1 parent 03c26d8 commit 9565c48

1 file changed

Lines changed: 11 additions & 17 deletions

File tree

express-zod-api/tests/json-schema-helpers.spec.ts

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,17 @@ describe("JSON Schema helpers", () => {
217217
expect(flat.examples).toEqual([{ a: 1 }, { b: 2 }, { c: 3 }]);
218218
});
219219

220-
test("should initialize examples when optional and flat has none", () => {
221-
const flat: { type: "object"; properties: {}; examples?: unknown[] } = {
222-
type: "object",
223-
properties: {},
224-
};
225-
mergeExamples(flat, { examples: [{ a: 1 }] }, true);
226-
expect(flat.examples).toEqual([{ a: 1 }]);
227-
});
220+
test.each([true, false])(
221+
"should initialize examples when flat has none (isOptional=%s)",
222+
(isOptional) => {
223+
const flat: { type: "object"; properties: {}; examples?: unknown[] } = {
224+
type: "object",
225+
properties: {},
226+
};
227+
mergeExamples(flat, { examples: [{ a: 1 }] }, isOptional);
228+
expect(flat.examples).toEqual([{ a: 1 }]);
229+
},
230+
);
228231

229232
test("should produce combinations when required", () => {
230233
const flat = {
@@ -238,15 +241,6 @@ describe("JSON Schema helpers", () => {
238241
{ a: 1, b: 3 },
239242
]);
240243
});
241-
242-
test("should handle required with no prior examples", () => {
243-
const flat: { type: "object"; properties: {}; examples?: unknown[] } = {
244-
type: "object",
245-
properties: {},
246-
};
247-
mergeExamples(flat, { examples: [{ a: 1 }] }, false);
248-
expect(flat.examples).toEqual([{ a: 1 }]);
249-
});
250244
});
251245

252246
describe("pullRequestExamples()", () => {

0 commit comments

Comments
 (0)