модульное тестирование: использование HttpTestingController с firebase (жасмин) - PullRequest
0 голосов
/ 18 апреля 2020

Я хочу проверить вход в систему, если он не пройден или пройден (вход с использованием Firebase HTTP-функции)

это мой код

auth.service.ts

login(email: string, password: string) {
return this.http
  .post<AuthResponseData>(
    `https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword?key=${
      environment.firebaseAPIKey
    }`,
    // tslint:disable-next-line: object-literal-shorthand
    { email: email, password: password }
  ).pipe(tap(this.setUserData.bind(this)));}

и эта страница тестирования: она не работает (Incomplete: спецификации не найдены), я не знаю, где неправильно

import { TestBed } from '@angular/core/testing';
import { HttpClientTestingModule , HttpTestingController, TestRequest } from 
'@angular/common/http/testing';
import { AuthService } from './auth.service';
import { environment } from 'src/environments/environment';
import { HttpErrorResponse } from '@angular/common/http';


describe('AuthService', () => {

let service: AuthService;
let httpMock: HttpTestingController;

beforeEach(() => {
 TestBed.configureTestingModule({
  imports: [HttpClientTestingModule],
  providers: [AuthService]
});
service = TestBed.get(AuthService);
httpMock = TestBed.get(HttpTestingController);

it('fail' ,  () => {
    // tslint:disable-next-line: deprecation
    service.login('s@S.com', '987456').subscribe(
    () => {}, (response: HttpErrorResponse) => {
     expect(response.error.message).toEqual('INVALID_PASSWORD');
    }
  );
    let call: TestRequest = httpMock.expectOne(`https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword?key=${
      environment.firebaseAPIKey
    }`);
    expect(call.request.method).toEqual('POST');
    call.error(
        new ErrorEvent('INVALID_PASSWORD')
    );
    httpMock.verify();
});
});

Я надеюсь помочь мне

...