Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense committed Apr 14, 2023
1 parent c07b08f commit 11d860a
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion test/mixed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
});
});
});

0 comments on commit 11d860a

Please sign in to comment.