morfi-test-utils is a testing utility library specifically designed for forms built with the `morfi` React form library. It provides helpers to simplify the testing of both `morfi` forms and individual `morfi`-connected fields within React components. The library is currently at version 3.0.3 and appears to be actively maintained, with the last major release (v2.0.0) in July 2022. It integrates with `@testing-library/react` and `jest` to offer utilities like mocking form fields, interacting with form values and errors, and asserting field properties and form submissions in an `act`-wrapped manner. Its key differentiator is its tight coupling with `morfi`'s internal structure, providing a more streamlined testing experience compared to generic form testing approaches.
npm install morfi-test-utilsVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to mock a Morfi-connected input component, render a form, interact with a field using `MorfiTestUtils`, and assert its properties and values before submission.
Ensure all error message values passed to `ErrorMessage` components or fields are valid React nodes (e.g., strings, numbers, JSX).
Upgrade `react` to version `16.2` or higher. Refactor tests to utilize the new automatic value/error provision via the `morfi` context rather than passing them manually to `MorfiTestUtils` methods.
Ensure your `jest.mock` implementation correctly wraps your component's props with `MorfiTestUtil.Field(arg)` and handles named/default exports as per your component's definition. Example for default export: `{ __esModule: true, default: (arg: any) => MorfiTestUtil.Field(arg) }`.If using `@testing-library/react`'s `fireEvent` directly, explicitly wrap the interaction and subsequent assertions within `act(() => { ... })` or use `userEvent` methods which are typically `act`-wrapped by default.Change `MorfiTestUtils.Field` to `MorfiTestUtil.Field` when mocking or wrapping fields. Ensure `import { MorfiTestUtils } from 'morfi-test-utils';` is used for the plural named export, and if you need the default export, you might explicitly import it as `import MorfiTestUtil, { MorfiTestUtils } from 'morfi-test-utils';`.Wrap the `fireEvent` call and subsequent assertions within `act(() => { /* fireEvent call */ });` or `await act(async () => { /* fireEvent call */ });` for async operations.Install `morfi` as a dependency in your project: `npm install morfi` or `pnpm add morfi` or `yarn add morfi`.