title: Jest/Enzyme | Cannot destructure property on null or undefined
body: <p>I am trying to test my function for <code>ComponentDidMount</code>. But I get this error:<code>Cannot destructure property params on null or undefined</code>.</p>
  
  <p>The function I want to test is this one:</p>
  
  <pre><code>  componentDidMount() {
      this.fetchUser();
    }
  </code></pre>
  
  <p>And it is depended on this one:</p>
  
  <pre><code>  fetchUser = () =&gt; {
      getUser(this.getUserUsername()).then(username =&gt; {
        this.setState({
          user: username.data
        });
      });
    };
  </code></pre>
  
  <p>which in return is depended on this one:</p>
  
  <pre><code>  getUserUsername = () =&gt; {
      const { match } = this.props;
      const { params } = match;
      console.log(params, 'params'); // return an object { username: "john" }
      console.log(match, 'match');
      **// return an object
      // { isExact: true
      //  params:
      // username: "john" .
      // __proto__: Object
      // path: "/management/users/:username"
      // url: "/management/users/john" }**
      return params.username;
    };
  </code></pre>
  
  <p>And here is my test:</p>
  
  <pre><code>  describe('componentDidMount', () =&gt; {
      it('should call fetchUsers function', () =&gt; {
        const match = { params: 'testName' };
        const params = match;
        const fetchUserFn = jest.fn(params);
        const wrapper = shallow(&lt;UserDetailsScreen fetchUsers={fetchUserFn} /&gt;, {
          disableLifecycleMethods: true
        });
        wrapper.instance().componentDidMount();
        expect(fetchUserFn).toHaveBeenCalledTimes(1);
      });
    });
  </code></pre>
  
  <p>But I get the above error. Not sure what I need to do, and while I found answers similar to this problem, the answers don't solve my problem.</p>
  
  <p>CODE for getUser:</p>
  
  <pre><code>
  export const getUser = username =&gt; {
    const options = {
      method: httpMethod.GET,
      url: endpoint.GET_USER(username)
      // The GET_USER is an endpoint for 
      // that specific username
    };
    return instance(options);
  };
  </code></pre>
  
  <p>The above returns a promise.</p>