title: Stub a function that runs a promise
body: <p>I've been attempting to write unit tests for a registration page on a new react application</p>
  
  <p>However I am very new to the concept of Sinon stubs/spies and have been having issues with intercepting a function call and forcing a resolve.</p>
  
  <p>This is my initial test:</p>
  
  <pre><code>test('Success notification is displayed if all information is valid', () =&gt; {
    wrapper.setState({ username: 'test', password: 'Test1234!@', confirmPassword: 'Test1234!@' });
    const stub = sinon.stub(Register.prototype, 'signUp').resolves('Test');
    wrapper.find('#submitRegistration').simulate('click');
  });
  </code></pre>
  
  <p>onClick runs this event handler: (Simplified)</p>
  
  <pre><code>public onSubmitHandler(e: React.FormEvent) {
    // Perform password match check
    if (password === confirmPassword) {
        this.signUp(this.state.username, password);
      } else {
        // Set success state
      }
    } else {
      // Set error state
    }
  }
  </code></pre>
  
  <p>And finally, Signup: </p>
  
  <pre><code>public signUp(username: string, password: string) {
    // Perform Cognito Signup
    return Auth.signUp({
      password,
      username,
    })
      .then(() =&gt; {
        // Set success State
      })
      .catch((err) =&gt; {
        // Set error state
      });
  }
  </code></pre>
  
  <p>How can I intercept the call to signUp and force it down the resolve path, Currently due to the fact i do not configure my AWS Amplify Auth module it catches every time with "No userPool"</p>