Skip to content

Commit 3e7c43d

Browse files
committed
add test to ts
1 parent 0e58d82 commit 3e7c43d

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

test/typescript/integration.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,27 @@ describe('TypeScript Definitions', () => {
361361
expect(res).toBe(true);
362362
});
363363

364+
365+
it("should work with optional (legacy)", () => {
366+
367+
let schemaOptional = {
368+
a: [
369+
{ type: "number", optional: true },
370+
{ type: "string", optional: true },
371+
]
372+
};
373+
374+
let checkOptional = v.compile(schemaOptional);
375+
376+
expect(checkOptional({})).toBe(true);
377+
expect(checkOptional({ a: 5 })).toBe(true);
378+
expect(checkOptional({ a: "five" })).toBe(true);
379+
expect(checkOptional({ a: false })).toEqual([
380+
{ type: "number", field: "a", actual: false, message: "The 'a' field must be a number." },
381+
{ type: "string", field: "a", actual: false, message: "The 'a' field must be a string." },
382+
]);
383+
});
384+
364385
});
365386

366387
describe('Test multiple rules with objects', () => {

0 commit comments

Comments
 (0)