title: instance().setState function doesn't work on unit test test
body: <p>i have an unit test to check if page is created well. But i have an problem. I define an empty array as users on <code>constructor</code> method and then assign an array with a method which is called on <code>componentDidMount</code> method. Everything works well when i test it myself on a device. But jest test throws error because of users array is undefined (i guess its impossible because i define it as [] at constructor method).</p>
  
  <p>Part of Users.js;</p>
  
  <pre><code>export default class Users extends React.Component {
    constructor(props) {
      super(props);
      this.state = {
        users: [],
        firmId: 0,
        key: 0,
        isLoading: true,
      };
    }
  
  componentDidMount() {
      this.getData();
  }
  
  getData() {
      return fetch("censored url" + this.state.firmId)
        .then(response =&gt; response.json())
        .then(responseJson =&gt; {
          this.setState(
            {
              users: responseJson.users,
              isLoading: false
            },
            function() {}
          );
        })
        .catch(error =&gt; {
          console.error(error);
        });
    }
  </code></pre>
  
  <p>Users.spec.js;</p>
  
  <pre><code>// other imports
  import { users } from "../../jest/mock-data";
  
  describe("&lt;Users&gt;", () =&gt; {
    function func(){
      return "2"
    }
    const navigation = { navigate: jest.fn(), getParam: func };
  
    it('fetches data from server when server returns a successful response', done =&gt; { // 1
      const mockSuccessResponse = users;
      const mockJsonPromise = Promise.resolve(mockSuccessResponse); // 2
      const mockFetchPromise = Promise.resolve({ // 3
        json: () =&gt; mockJsonPromise,
      });
      jest.spyOn(global, 'fetch').mockImplementation(() =&gt; mockFetchPromise); // 4
  
      const component = shallow(&lt;Users navigation={navigation}/&gt;);    // 5
  
      component.instance().setState({
        users: [],
        isLoading: false
      });
  
      expect(global.fetch).toHaveBeenCalledTimes(2); //success
      expect(global.fetch).toHaveBeenCalledWith("censored url/2"); //success
  
      process.nextTick(() =&gt; { // 6
        expect(component.state()).toEqual({
          users: users,
          isLoading: false,
          firmId: "2",
          key: "2"
        });  // THROWS ERROR
  
        global.fetch.mockClear(); // 7
        done(); // 8
      });
    });
   }); 
  </code></pre>
  
  <p>I pointed the test which is throws error with THROWS ERROR comment.</p>
  
  <p>Error on cmd;</p>
  
  <pre><code> ● &lt;Users&gt; › fetches data from server when server returns a successful response
  
      expect(received).toEqual(expected) // deep equality
  
      - Expected
      + Received
  
        Object {
          "firmId": "2",
          "isLoading": false,
          "key": "2",
      -   "users": Array [
      -     Object {
      -       "createdAt": 1547939031000,
      -       "email": "test@firm.com",
      -       "firstName": "Test",
      -       "id": 5,
      -       "lastName": "User",
      -       "phone": "45454545454",
      -       "status": null,
      -       "updatedAt": 1547939031000,
      -     },
      -   ],
      +   "users": undefined,
        }
  
        48 |
        49 |     process.nextTick(() =&gt; { // 6
      &gt; 50 |       expect(component.state()).toEqual({
           |                                 ^
        51 |         users: users,
        52 |         isLoading: false,
        53 |         firmId: "2",
  </code></pre>
  
  <p>I guess <code>component.instance().setState</code> is not works well but i'm not sure. I will be glad if you know the answer and help me to fix that problem.</p>
  
  <p><strong>edit:</strong> I tried to add a new variable at setState function which is contains in test file. And when i test it on expect it worked well. So its just not working for users variable. </p>