From 11d860a37bb3a7329436404dca2b8a2d0de8b638 Mon Sep 17 00:00:00 2001 From: jquense Date: Fri, 14 Apr 2023 10:11:24 -0400 Subject: [PATCH] add test --- test/mixed.ts | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/test/mixed.ts b/test/mixed.ts index 154169e8a..f1848e50f 100644 --- a/test/mixed.ts +++ b/test/mixed.ts @@ -673,7 +673,7 @@ describe('Mixed Types ', () => { it('concat should carry over transforms', async () => { let inst = string().trim(); - await expect(inst.concat(string().min(4)).cast(' hello ')).toBe('hello'); + expect(inst.concat(string().min(4)).cast(' hello ')).toBe('hello'); await expect(inst.concat(string().min(4)).isValid(' he ')).resolves.toBe( false, @@ -1217,4 +1217,38 @@ describe('Mixed Types ', () => { await expect(inst.isValid({ prop: 'prop value' })).resolves.toBe(true); }); }); + + describe('description options', () => { + const schema = object({ + name: string(), + type: bool(), + fancy: string() + .label('bad label') + .when('type', { + is: true, + then: (schema) => schema.required().label('good label'), + otherwise: (schema) => schema.label('default label'), + }), + }); + + it('should pass options', async () => { + expect( + // @ts-ignore + schema.fields.fancy.describe({ parent: { type: true } }).label, + ).toBe('good label'); + expect( + // @ts-ignore + schema.fields.fancy.describe({ parent: { type: true } }).optional, + ).toBe(false); + + expect( + // @ts-ignore + schema.fields.fancy.describe({ parent: { type: false } }).label, + ).toEqual('default label'); + expect( + // @ts-ignore + schema.fields.fancy.describe({ parent: { type: false } }).optional, + ).toBe(true); + }); + }); });