проверка «это» значение после обещания Жасмин - PullRequest
0 голосов
/ 18 декабря 2018

У меня следующая проблема:

Я хочу проверить, заполняется ли сообщение об ошибке после отклоненного обещания.

login.component.spec

  it('Login should display error', () => {
    spyOn(service, 'returnfalse').and.returnValue(Promise.reject('auth/popup-closed-by-user'));
    component.signInWithGithub();
    expect(component.loginError).toBe('The popup has been closed before authentication');
  });

login.component

export class LoginComponent implements OnInit {
  public loginError: string | boolean = false;

  constructor(public authService: AuthService, public router: Router, private data: GithubService) {
  }
  public signInWithGithub(): void {
    this.authService.loginwithGithubProvider()
      .then(res => { this.loginError = null; })
      .catch(err => {
          if (err === Errorcode.FIREBASE_POPUP_CLOSED) {
            this.loginError = 'The popup has been closed before authentication';
          }
          if (err === Errorcode.FIREBASE_REQUEST_EXESS) {
            this.loginError = 'To many requests to the server';
          }
        }
      );
  }}

Но после того, как обещание отклонено, this.loginError по-прежнему равно нулю.

ЛюбойИдея, как я мог бы решить это?

...