title: TypeError: Invalid attempt to spread non-iterable instance. In order to be iterable, non-array objects must have a [Symbol.iterator]() method
body: <p>I'm trying to test a useState value of and object in react native with enzyme and jest.
  I got it working when using a state with only one value but i'm failing with many values in useState with above error.
  In the onchange i use the spread operator and i think it's this i need to somehow implement in my test under mockEvent, but i can't find a way and i am stuck. Any help is greatly appreciated.</p>
  
  <p>Component:</p>
  
  <pre><code>import React from "react";
  import { View, Text, TextInput, TouchableOpacity } from "react-native";
  
  const RegisterScreen = () =&gt; {
  const [user, setUser] = React.useState({ name: "", email: "", password: "", password2: "" });
  return (
  &lt;View testID='register-component'&gt;
    &lt;Text testID='test'&gt;RegisterScreen&lt;/Text&gt;
    &lt;TextInput
      testID='register-input-name'
      onChangeText={(e) =&gt; {
        setUser(...user, [name], e.target.value);
      }}
      name='name'
      value={user.name}
    /&gt;
    &lt;TextInput testID='register-input-email' /&gt;
    &lt;TextInput testID='register-input-password' label='Password' autoCapitalize='none' autoCorrect={false} secureTextEntry={true} /&gt;
    &lt;TextInput testID='register-input-confirm' /&gt;
    &lt;TouchableOpacity testID='register-submit-button' /&gt;
  &lt;/View&gt;
  );
  };
  
  export default RegisterScreen;
  </code></pre>
  
  <p>Test:</p>
  
  <pre><code>test("name input changes state", () =&gt; {
      const mockSetUser = jest.fn();
      React.useState = jest.fn(() =&gt; [{ name: "", email: "", password: "", password2: "" }, mockSetUser]);
  
      const wrapper = shallow(&lt;RegisterScreen /&gt;);
      const nameinput = wrapper.find("[testID='register-input-name']");
  
      const mockEvent = { target: { name: "name", value: "test" } };
  
      nameinput.simulate("changeText", mockEvent);
      const nameVal = nameinput.find("[value='test']");
      expect(nameVal.length).toBe(1);
    });
  </code></pre>