Declaration: this is part of my assignment for an online class that is already submitted for grading but it has already failed on my setup so...i will be asked to redo it until I get it but i don't have any other idea after a week.
Background: I am not supposed to change the code base. I am supposed to write a unit test only. All is in https://stackblitz.com/edit/angular-3fg4ny To paste all the code here: index.html: <html> <head> <script src="https://apis.google.com/js/platform.js" async defer></script> <meta name="google-signin-client_id" content= "958548668159-fh4ut9p5bujqimphcpoaoivt1brshrru.apps.googleusercontent.com.apps.googleusercontent.com" > </head> <my-app>loading</my-app> </html> app.component.ts: import { Component, OnInit } from '@angular/core'; declare let gapi: any; @Component({ selector: 'my-app', templateUrl: './app.component.html', styleUrls: [ './app.component.css' ] }) export class AppComponent implements OnInit { auth2 : any; ngOnInit(){ this.loadAuth(); } loadAuth(){ try { if (typeof gapi != "undefined") { gapi.load("auth2", () => { console.log(48) this.auth2 = gapi.auth2.init({ client_id: "958548668159-fh4ut9p5bujqimphcpoaoivt1brshrru.apps.googleusercontent.com", cookiepolicy: "single_host_origin", scope: "profile email" }); console.log(55); this.attachSignin(document.getElementById('google-login')).then( profile=>{ console.log(48, profile) }).catch(error=>{ console.log(50, error) }).finally(()=>{ console.log(52, ' finally') }) }); } else { console.log(32, "gapi undefined"); } } catch (err) { console.log(26, err); } console.log('step 2') } public attachSignin(element): Promise<any> { return new Promise((resolve, reject) => { if (typeof gapi == "undefined") { reject({'reason' : 'gapiUndefined'}); } else { this.auth2.attachClickHandler( element, {}, googleUser => { console.log(googleUser) let profile = googleUser.getBasicProfile(); const details = { name : profile.getName(), email : profile.getEmail(), token : googleUser.getAuthResponse().id_token, id_token : profile.getId() } resolve(details); }, error => { // for e.g. if user closes the window reject({'reason': 'closedByUser'}); } ); } }); } } Now in my tests, I am reaching attachSignin but I am never console logging googleUser which is : console.log(googleUser) I can't really know how the attachClickHandler is setup or really where it is coming from because I checked platform.js from google and can't find a definition of it either. From the looks of it, I thought it is an observable but can't mock it. Basically, in the real assignment, once googleUser is returned, there is a logic in place around the returned email and name that resolves or rejects the promise. All I wwant to do, I think correctly, is to make attachClickHandler to return a google user but I am still very fuzzy on it. Can you take a look at my spec file and help? -- You received this message because you are subscribed to the Google Groups "Angular and AngularJS discussion" group. To unsubscribe from this group and stop receiving emails from it, send an email to angular+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/angular/f195d172-4de3-4479-b4e1-c3bb2a2714fa%40googlegroups.com.