I faile to write even the most simple tests for react jsonschema form. Because changes to input elements seem not to be reflected in the dom.
Given a minimal form like this:
const schema = {
title: "Todo", type: "object",
properties: {
title: { type: "string", title: "Title", default: "A new task" }
}
};
const formData = { title: "First task aaa" };
export class MyForm extends React.Component {
render() { return <Form schema={schema} formData={formData} />; }
}
a minimal test would look like
test("changes input", async () => {
render(<MyForm />);
const input = screen.getByRole("textbox");
expect(input.value).toBe("First task aaa");
await userEvent.type(input, "567890", { delay: 10 });
expect(input.value).toBe("567890");
});
(Complete sample over at Codesandbox.)
After typing in the Form field the text First task aaa should be replaced by 567890. Unfortunately it is not.input.value keeps the value First task aaa.
I thied many variants of firing events and waiting for results but always the value of the input element stays unchanged.
What am I missing to test the <MyForm /> component? Seems pretty standard to me.
I can reproduce your problem as well and it looks like react-jsonschema-form is not playing well with
fireEventoruserEvent.However, using the react-doms Simulate function, it does work: