diff --git a/packages/uniforms-bridge-zod/__tests__/ZodBridge.ts b/packages/uniforms-bridge-zod/__tests__/ZodBridge.ts index b874f679b..ae11c541d 100644 --- a/packages/uniforms-bridge-zod/__tests__/ZodBridge.ts +++ b/packages/uniforms-bridge-zod/__tests__/ZodBridge.ts @@ -278,7 +278,7 @@ describe('ZodBridge', () => { it('works with enum (array)', () => { const schema = object({ a: enum_(['x', 'y', 'z']) }); const bridge = new ZodBridge({ schema }); - expect(bridge.getInitialValue('a')).toEqual('x'); + expect(bridge.getInitialValue('a')).toEqual(undefined); }); it('works with enum (native, numbers)', () => { diff --git a/packages/uniforms-bridge-zod/src/ZodBridge.ts b/packages/uniforms-bridge-zod/src/ZodBridge.ts index eb0f45072..ec3da0af0 100644 --- a/packages/uniforms-bridge-zod/src/ZodBridge.ts +++ b/packages/uniforms-bridge-zod/src/ZodBridge.ts @@ -152,10 +152,6 @@ export default class ZodBridge extends Bridge { return field._def.defaultValue(); } - if (field instanceof ZodEnum) { - return field.options[0]; - } - if (field instanceof ZodNativeEnum) { const values = Object.values(field.enum as Record); return values.find(isNativeEnumValue) ?? values[0]; diff --git a/packages/uniforms-mui/__tests__/SelectField.tsx b/packages/uniforms-mui/__tests__/SelectField.tsx index efb0467c0..e5625772b 100644 --- a/packages/uniforms-mui/__tests__/SelectField.tsx +++ b/packages/uniforms-mui/__tests__/SelectField.tsx @@ -77,7 +77,7 @@ describe('@RTL - SelectField tests', () => { schema: z.object({ x: z.enum(['a', 'b']) }), }); - expect(screen.getByText('a')).toBeInTheDocument(); + expect(screen.queryByText('a')).not.toBeInTheDocument(); expect(screen.queryByText('b')).not.toBeInTheDocument(); }); @@ -233,7 +233,7 @@ describe('@RTL - SelectField tests', () => { schema: z.object({ x: z.enum(['a', 'b']) }), }); - expect(screen.getByLabelText('a *')).toBeChecked(); + expect(screen.getByLabelText('a *')).not.toBeChecked(); expect(screen.getByLabelText('b *')).not.toBeChecked(); }); diff --git a/packages/uniforms/__suites__/RadioField.tsx b/packages/uniforms/__suites__/RadioField.tsx index 09c69021b..c661a611f 100644 --- a/packages/uniforms/__suites__/RadioField.tsx +++ b/packages/uniforms/__suites__/RadioField.tsx @@ -116,7 +116,7 @@ export function testRadioField( schema: z.object({ x: z.enum(['a', 'b']) }), }); - expect(screen.getAllByRole('radio')[0]).toHaveAttribute('checked'); + expect(screen.getAllByRole('radio')[0]).not.toHaveAttribute('checked'); expect(screen.getAllByRole('radio')[1]).not.toHaveAttribute('checked'); }); @@ -161,8 +161,9 @@ export function testRadioField( onChange, }); await userEvent.click(screen.getByRole('radio', { name: 'a' })); + await userEvent.click(screen.getByRole('radio', { name: 'a' })); - expect(onChange).not.toHaveBeenCalled(); + expect(onChange).toHaveBeenCalledTimes(1); }); test(' - renders a label', () => { diff --git a/packages/uniforms/__suites__/SelectField.tsx b/packages/uniforms/__suites__/SelectField.tsx index 8837e7a3b..6fda81e2a 100644 --- a/packages/uniforms/__suites__/SelectField.tsx +++ b/packages/uniforms/__suites__/SelectField.tsx @@ -38,7 +38,7 @@ export function testSelectField( element: , schema: z.object({ x: z.enum(['a', 'b']) }), }); - expect(screen.getByText('y')).toBeInTheDocument(); + expect(screen.getByLabelText(/y\*?/)).toBeInTheDocument(); }); skipTestIf(isTheme(['mui', 'antd']))( @@ -237,7 +237,7 @@ export function testSelectField( element: , schema: z.object({ x: z.enum(['a', 'b']) }), }); - expect(screen.getByText('y')).toBeInTheDocument(); + expect(screen.queryByPlaceholderText('y')).not.toBeInTheDocument(); }); skipTestIf(isTheme(['antd', 'mui']))( @@ -260,10 +260,10 @@ export function testSelectField( }); const select = screen.getByRole('combobox'); if (options?.theme === 'antd') { - expect(screen.getByText('a')).toBeInTheDocument(); + expect(screen.queryByText('a')).not.toBeInTheDocument(); expect(screen.queryByText('b')).not.toBeInTheDocument(); } else { - expect(select).toHaveValue('a'); + expect(select).not.toHaveValue(); } }, ); @@ -538,7 +538,7 @@ export function testSelectField( const checkboxes = fields.filter( element => element instanceof HTMLInputElement, ); - expect(checkboxes?.[0]).toBeChecked(); + expect(checkboxes?.[0]).not.toBeChecked(); expect(checkboxes?.[1]).not.toBeChecked(); });