diff --git a/packages/uniforms/__suites__/QuickForm.tsx b/packages/uniforms/__suites__/QuickForm.tsx index a13b0a6ef..c0f17e639 100644 --- a/packages/uniforms/__suites__/QuickForm.tsx +++ b/packages/uniforms/__suites__/QuickForm.tsx @@ -4,10 +4,10 @@ import { ZodBridge } from 'uniforms-bridge-zod'; import z from 'zod'; export function testQuickForm(QuickForm: ComponentType) { + const bridge = new ZodBridge({ schema: z.object({}) }); + test(' - renders', () => { - const schema = z.object({}); - const bridge = new ZodBridge({ schema }); - const screen = render(); - expect(screen.getByTestId('form')).toBeInTheDocument(); + const { container } = render(); + expect(container.getElementsByTagName('form')).toHaveLength(1); }); } diff --git a/packages/uniforms/__tests__/QuickForm.tsx b/packages/uniforms/__tests__/QuickForm.tsx index b1a0cb6cd..f0b9ff76d 100644 --- a/packages/uniforms/__tests__/QuickForm.tsx +++ b/packages/uniforms/__tests__/QuickForm.tsx @@ -1,82 +1,96 @@ +import { render } from '@testing-library/react'; import React from 'react'; -import SimpleSchema from 'simpl-schema'; import { QuickForm } from 'uniforms'; -import { SimpleSchema2Bridge } from 'uniforms-bridge-simple-schema-2'; - -import mount from './_mount'; +import { ZodBridge } from 'uniforms-bridge-zod'; +import { z } from 'zod'; describe('QuickForm', () => { + const AutoField = jest.fn(() => null) as any; + const ErrorsField = jest.fn(() => null) as any; + const SubmitField = jest.fn(() => null) as any; + // @ts-expect-error QuickForm is not a valid Component. class TestForm extends QuickForm { // eslint-disable-next-line react/display-name - getAutoField = () => () => ; + getAutoField = () => () => ; // eslint-disable-next-line react/display-name - getErrorsField = () => () => ; + getErrorsField = () => () => ; // eslint-disable-next-line react/display-name - getSubmitField = () => () => ; + getSubmitField = () => () => ; } - const schema = new SimpleSchema2Bridge({ - schema: new SimpleSchema({ - a: String, - b: String, - c: String, - }), + const schema = z.object({ + a: z.string(), + b: z.string(), + c: z.string(), + }); + const bridge = new ZodBridge({ schema }); + + afterEach(() => { + AutoField.mockClear(); + ErrorsField.mockClear(); + SubmitField.mockClear(); }); describe('when rendered with custom fields', () => { it('renders `AutoField` for each field', () => { - const wrapper = mount(); + render(); - expect(wrapper.find('.auto').length).toBeGreaterThan(0); + expect(AutoField).toHaveBeenCalledTimes(3); }); it('renders `ErrorsField`', () => { - const wrapper = mount(); + render(); - expect(wrapper.find('.errors').length).toBeGreaterThan(0); + expect(ErrorsField).toHaveBeenCalledTimes(1); }); it('renders `SubmitField`', () => { - const wrapper = mount(); + render(); - expect(wrapper.find('.submit').length).toBeGreaterThan(0); + expect(SubmitField).toHaveBeenCalledTimes(1); }); }); describe('when rendered with custom fields in `props`', () => { it('renders `ErrorsField`', () => { - const wrapper = mount( + const ErrorsOverrideField = jest.fn(() =>
) as React.FC; + + render( } + schema={bridge} + errorsField={() => } />, ); - expect(wrapper.find('.errorsOverride').length).toBeGreaterThan(0); + expect(ErrorsOverrideField).toHaveBeenCalledTimes(1); }); it('renders `SubmitField`', () => { - const wrapper = mount( + const SubmitOverrideField = jest.fn(() =>
) as React.FC; + + render( } + schema={bridge} + submitField={() => } />, ); - expect(wrapper.find('.submitOverride').length).toBeGreaterThan(0); + expect(SubmitOverrideField).toHaveBeenCalledTimes(1); }); }); describe('when rendered with children', () => { - const wrapper = mount( - -
- , - ); - it('renders children', () => { - expect(wrapper.find('div')).toHaveLength(1); + const Child = jest.fn(() =>
) as React.FC; + + render( + + + , + ); + + expect(Child).toHaveBeenCalledTimes(1); }); }); });