title: How to test form submission in React with Jest and Enzyme? Cannot read property 'preventDefault' of undefined
body: <p>I'm writing a test to check if the error Notification component displays if the login form is submitted with no data.</p>
  <pre><code>describe('User signin', () =&gt; {
      it('should fail if no credentials are provided', () =&gt; {
          const loginComponent = shallow(&lt;Login /&gt;);
          expect(loginComponent.find('.form-login').length).toBe(1);
          loginComponent.find('.form-login').simulate('submit');
          expect(loginComponent.find(Notification).length).toBe(1);
      });
  });
  </code></pre>
  <p>It looks like the <code>.simulate</code> is working as the test reaches my <code>handleSubmit</code> function, however I am running into this error in the test:</p>
  <blockquote>
  <p>TypeError: Cannot read property 'preventDefault' of undefined</p>
  </blockquote>
  <p><a href="https://i.stack.imgur.com/U0ZBe.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/U0ZBe.jpg" alt="enter image description here" /></a></p>
  <h3>The handleSubmit function</h3>
  <pre><code>handleSubmit(e) {
      e.preventDefault();  // &lt;-- problem here
      const user = this.state.username;
      const pass = this.state.password;
      const gotoDashboard = () =&gt; this.props.history.push('/dashboard');
  
      const postLogin = (user, pass) =&gt; {
          api.userLogin(user, pass)
  </code></pre>
  <p>My test will past if I remove the <code>e.preventDefault();</code> line, however I need that line in there to prevent the default form submission event.</p>