Skip to content

Commit 58623f1

Browse files
authored
Improving the coverage after moving to vitest 4 (#3020)
Due to #2815
1 parent 6ccabc9 commit 58623f1

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

express-zod-api/tests/__snapshots__/result-handler.spec.ts.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,15 @@ exports[`ResultHandler > 'defaultResultHandler' > should generate negative respo
145145
],
146146
}
147147
`;
148+
149+
exports[`ResultHandler > arrayResultHandler should attempt to take examples from the items prop 1`] = `
150+
{
151+
"examples": [
152+
[
153+
"One",
154+
"Two",
155+
"Three",
156+
],
157+
],
158+
}
159+
`;

express-zod-api/tests/documentation-helpers.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,15 @@ describe("Documentation helpers", () => {
149149
});
150150

151151
describe("depictUnion()", () => {
152+
test("should ignore non-union schemas", () => {
153+
expect(
154+
depictUnion(
155+
{ zodSchema: z.never(), jsonSchema: { id: "this one" } },
156+
responseCtx,
157+
),
158+
).toEqual({ id: "this one" });
159+
});
160+
152161
test("should set discriminator prop for such union", () => {
153162
const zodSchema = z.discriminatedUnion("status", [
154163
z.object({ status: z.literal("success"), data: z.any() }),

express-zod-api/tests/result-handler.spec.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,8 @@ describe("ResultHandler", () => {
186186
test("should forward output schema examples", () => {
187187
const apiResponse = subject.getPositiveResponse(
188188
z
189-
.object({
190-
str: z.string(),
191-
items: z.array(z.string()),
192-
})
193-
.example({
194-
str: "test",
195-
items: ["One", "Two", "Three"],
196-
}),
189+
.object({ str: z.string(), items: z.array(z.string()) })
190+
.example({ str: "test", items: ["One", "Two", "Three"] }),
197191
);
198192
expect(apiResponse).toHaveLength(1);
199193
expect(apiResponse[0].schema.meta()).toMatchSnapshot();
@@ -206,6 +200,14 @@ describe("ResultHandler", () => {
206200
});
207201
});
208202

203+
test("arrayResultHandler should attempt to take examples from the items prop", () => {
204+
const apiResponse = arrayResultHandler.getPositiveResponse(
205+
z.object({ items: z.array(z.string()).example(["One", "Two", "Three"]) }),
206+
);
207+
expect(apiResponse).toHaveLength(1);
208+
expect(apiResponse[0].schema.meta()).toMatchSnapshot();
209+
});
210+
209211
test("arrayResultHandler should fail when there is no items prop in the output", () => {
210212
const responseMock = makeResponseMock();
211213
const loggerMock = makeLoggerMock();

0 commit comments

Comments
 (0)