title: How to test error state with mounted Component inside MemoryRouter with Enzyme and Mocha
body: <p>I want to test the error state of a React Component with Enzyme mount. The error isnt displayed even though the State is set.</p>
  
  <p>This is the render Method of the React Component</p>
  
  <pre><code>  render() {
  
      return (
        &lt;div&gt;
          &lt;div&gt;
            &lt;h1&gt;Signup&lt;/h1&gt;
  
            {this.state.error ? &lt;p&gt;{this.state.error}&lt;/p&gt; : undefined}
  
            &lt;form onSubmit={this.onSubmit}&gt;
              &lt;input type="text" ref="username" name="username" placeholder="Username"/&gt;
              &lt;input type="email" ref="email" name="email" placeholder="Email"/&gt;
              &lt;input type="password" ref="password" name="password" placeholder="Password"/&gt;
              &lt;button&gt;Create Account&lt;/button&gt;
            &lt;/form&gt;
  
            &lt;p&gt;&lt;Link to="/login"&gt;Already have an account?&lt;/Link&gt;&lt;/p&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      )
  
    }
  </code></pre>
  
  <p>This is the Test with Mocha and Enzyme</p>
  
  <pre><code>    it('should show error message', function () {
  
        const error = 'This is not working'
        const spy2 = expect.createSpy()
  
        const wrapper2 = Enzyme.mount(
          &lt;MemoryRouter&gt;
            &lt;Signup
              createUser={spy2}
            /&gt;
          &lt;/MemoryRouter&gt;
        )
  
        // Access Signup Component inside Memory Router
        const component = wrapper2.find(Signup)
  
        component.setState({error})
        expect(component.find('p').first().text()).toBe(error)
      })
  </code></pre>
  
  <p>I expect that the text of the error paragraph matches with the set error state message</p>