title: Angular Google Sign with Test
body: <p>I am having issues mocking attachClickHandler function of gauth. The following is my code. I am unable to mock the attachClickHander onSuccess and onFailure callbacks. Thus, unable to test the prepareLoginButton method.</p>
  
  <pre><code>export class GoogleSignInButtonComponent implements OnInit {
  
    auth2: any;
  
    constructor(
      private socialSignInController: SocialSignInControllerService,
      private ngZone: NgZone,
      private toastr: ToastrService,
      private authenticationService: AuthenticationService) { }
  
    ngOnInit(): void {
      this.googleSDK();
    }
    googleSDK() {
  
      window['googleSDKLoaded'] = () =&gt; {
        window['gapi'].load('auth2', () =&gt; {
          this.auth2 = window['gapi'].auth2.init({
            client_id: environment.social.google.clientId,
            cookiepolicy: 'single_host_origin',
            scope: 'profile email'
          });
          this.prepareLoginButton();
        });
      }
  
      (function (d, s, id) {
        var js, fjs = d.getElementsByTagName(s)[0];
        if (d.getElementById(id)) { return; }
        js = d.createElement(s); js.id = id;
        js.src = "https://apis.google.com/js/platform.js?onload=googleSDKLoaded";
        fjs.parentNode.insertBefore(js, fjs);
      }(document, 'script', 'google-jssdk'));
  
    }
  
     prepareLoginButton() {
      this.auth2.attachClickHandler(document.getElementById('googleBtn'), {},
        (googleUser) =&gt; {
          this.ngZone.run(() =&gt; {
            const token = googleUser.getAuthResponse().id_token;
            this.socialSignInController.googleTokenSignIn(token).subscribe(res =&gt; {
              this.authenticationService.onSocialLoginSuccess(res.token);
              window.location.href = '/dashboard'
            });
          }, (error) =&gt; {
            this.toastr.error('An error occurred. Please try again', 'Could not sign you in')
            console.log(error);
          });
        })
  
    }
  
  }
  </code></pre>