Skip to content

Testing MLForm

Test the engine when you need deterministic state. Test mounted primitives when you need DOM behavior.

Transport unit test pattern:

const transport = {
submit: vi.fn().mockResolvedValue({
reports: { prediction: { label: "approved" } },
}),
};
const mounted = mountForm(container, { schema, transport });
await mounted.form.submit();
expect(transport.submit).toHaveBeenCalledWith(
expect.objectContaining({ serializedValues: expect.any(Object) }),
);

Recommended coverage:

FeatureTest
Field constraintsform.validate() returns expected field errors.
Cross-field validatorsInvalid combinations block submit.
HooksHooks receive values, result, and submit count.
Custom fieldsDefinition normalizes, serializes, validates, and describes.
Custom renderersPrimitive registry maps descriptor component to a valid custom element.