React input onchange simulation not updating value using Jest and enzyme

I have a functional component as below

const Input = () => {
  const [value, updateValue] = useState("");
  return (
    <input
      type="text"
      id="input"
      value={value}
      onChange={(e) => {
        updateValue(e.target.value);
      }}
    />
  );
};

export default Input;

and test as below

const event = { target: { value: "Q" } };
input.simulate("change", event);
expect(input.prop("value")).toBe("Q");

the problem is that simulation of the event is not updating state.
I tried wrapper.update() as well but it is not working.

you can run test here

58 thoughts on “React input onchange simulation not updating value using Jest and enzyme”

  1. Pingback: ivermectin 6 price
  2. Pingback: stromectol clav
  3. Pingback: ivermectina 3

Leave a Comment