title: how to handle sinon.stub().throws() in unit test by Sinon JS
body: <p>Am trying to invoke <code>fail</code> condition in my snippet.
  But when I use <code>sinon.stub().throws()</code> method It shows me error.
  Am unable to handle it in code.
  <strong>Here is my snippet:</strong></p>
  
  <pre><code>login() {
      let loginData = this.loginData;
      return this.authService.login(loginData).then(userData =&gt; {
  
        let msg = `${this.niceToSeeYouAgain} ${userData.email}!`;
        this.userAlertsService.showSuccessToast(msg);
        this.navigationService.afterLoggedIn();
  
        //above lines are covered in test cases
  
      }, errorInfo =&gt; {
        // below line are needed to test
        this.userAlertsService.showAlertToast(errorInfo);
      });
  }
  </code></pre>
  
  <p>**And here is my unit-test snippet: **</p>
  
  <pre><code>it('.login() - should throw exception - in failure case', sinon.test(() =&gt; {
  
      let errorInfo = "some error";
  
      let stub = sinon.stub(authService, 'login').throws();
  
      let spy1 = sinon.spy(controller.userAlertsService, 'showAlertToast');
  
  
      //call function
      controller.login();
      // $timeout.flush();
  
      // expect things
      console.log(stub.callCount, stub.args[0]);
  
    }));
  </code></pre>
  
  <p>Please let me know what am doing wrong</p>