Skip to content

Commit 768f278

Browse files
committed
Full code coverage
1 parent 0678f4b commit 768f278

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ The following JSON Schema features are **not yet implemented**:
262262
## Standards Compliance
263263

264264
- **JSON Schema Draft 2020-12** - Partial support for core features of the latest JSON Schema standard
265-
- **Official Test Suite** - Passes the majority of tests from the official JSON Schema Test Suite ([253 tests currently skipped](./failing-tests-skip-list.json) for unsupported features)
265+
- **Official Test Suite** - Passes the majority of tests from the official JSON Schema Test Suite ([246 tests currently skipped](./failing-tests-skip-list.json) for unsupported features)
266266

267267
## License
268268

src/coverage-object-branches.test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { describe, expect, it } from "vitest";
2+
import { convertJsonSchemaToZod } from "./index";
3+
4+
describe("coverage for object handler branches", () => {
5+
it("should cover maxProperties with existing object type", () => {
6+
// This should trigger the case where types.object is already set
7+
// when MaxPropertiesHandler runs, covering the left side of the || operator
8+
const schema = convertJsonSchemaToZod({
9+
type: "object", // This creates an object type first
10+
maxProperties: 2, // This should use the existing types.object
11+
additionalProperties: true // Allow extra properties for testing
12+
});
13+
14+
// Test that it works
15+
expect(schema.safeParse({ foo: "bar" }).success).toBe(true);
16+
expect(schema.safeParse({ foo: "bar", baz: 1, qux: 2 }).success).toBe(false);
17+
});
18+
19+
it("should cover minProperties with existing object type", () => {
20+
// Same for MinPropertiesHandler
21+
const schema = convertJsonSchemaToZod({
22+
type: "object", // This creates an object type first
23+
minProperties: 1, // This should use the existing types.object
24+
additionalProperties: true // Allow extra properties for testing
25+
});
26+
27+
// Test that it works
28+
expect(schema.safeParse({ foo: "bar" }).success).toBe(true);
29+
expect(schema.safeParse({}).success).toBe(false);
30+
});
31+
32+
it("should cover both min and max properties with existing object type", () => {
33+
// Cover both handlers with existing object type
34+
const schema = convertJsonSchemaToZod({
35+
type: "object",
36+
minProperties: 1,
37+
maxProperties: 2,
38+
additionalProperties: true // Allow extra properties for testing
39+
});
40+
41+
// Test all constraints
42+
expect(schema.safeParse({}).success).toBe(false); // violates minProperties
43+
expect(schema.safeParse({ foo: "test" }).success).toBe(true); // valid
44+
expect(schema.safeParse({ foo: "test", bar: 42 }).success).toBe(true); // valid
45+
expect(schema.safeParse({ foo: "test", bar: 42, baz: "extra" }).success).toBe(false); // violates maxProperties
46+
});
47+
});

0 commit comments

Comments
 (0)