Ошибка: ожидается один соответствующий запрос по критериям - PullRequest
0 голосов
/ 27 сентября 2019

Ошибка: ожидается один запрос на соответствие критериям "Соответствующий URL: http://192.168.1.222:8080/customeType/getPropertyList/193", не найденесли вы хотите получить доступ к определенному методу, необходимо авторизоваться

Spec.ts

import { StockService } from './stock.service';
import { Constants } from './constants/app.constants';
import { deckAuthInterceptor } from './deckAuth.interceptor';
import { ErrorLogsService } from './ErrorLog.service';
import { UserLogsService } from './userLogs.service';
import { Ng4LoadingSpinnerService } from 'ng4-loading-spinner';
import { UserService } from './user.service';
import { RouterTestingModule } from '@angular/router/testing';
import { RouterModule, Data } from '@angular/router';
import { ToastsManager, ToastOptions } from 'ng6-toastr';
import { GlobalService } from './global.service';
import { HttpModule } from '@angular/http';
import { CustomTypesService } from './customtypes.service';
import { TestBed, inject } from '@angular/core/testing';
import {
  HttpClientTestingModule,
  HttpTestingController
} from '@angular/common/http/testing';
import { HttpClientModule, HTTP_INTERCEPTORS} from '@angular/common/http';
import { ViewContainerRef } from '@angular/core';
import { Http,
  Response,
  ResponseOptions,
  XHRBackend
} from '@angular/http';
import { MockBackend } from '@angular/http/testing';

fdescribe('Customtype', () => {
  let httpTestingController: HttpTestingController;
  let service: CustomTypesService;
  const mockAuthService = {
    tokenType: 'fake',
    tokenValue: 'fake'
  };
  beforeEach(() => {
    TestBed.configureTestingModule({
      providers: [
        CustomTypesService,
        GlobalService,
        ToastsManager,
        ToastOptions,
        UserService,
        Ng4LoadingSpinnerService,
        UserLogsService,
        ErrorLogsService,
        ViewContainerRef,
        {
          provide: HTTP_INTERCEPTORS,
          useClass: deckAuthInterceptor,
          multi: true
        },
        {
          provide: UserService,
          useValue: mockAuthService
        },


      ],
      imports: [HttpClientTestingModule,
        HttpClientModule,
        HttpModule,
        RouterModule,
        RouterTestingModule,
      ]
    });

    httpTestingController = TestBed.get(HttpTestingController);
    service = TestBed.get(CustomTypesService);
  });
  it('should be created', () => {
    expect(service).toBeTruthy();
  });

  it('returned Observable should match the right data', () => {
    const datamock: Data[] = [
      {
        'name': 'High',
        'value': '1',
        'description': 'High'
      },
      {
        'name': 'Low',
        'value': '3',
        'description': 'Low'
      },
      {
        'name': 'Medium',
        'value': '2',
        'description': 'Medium'
      }
    ];


    service.getPropertyList(193).subscribe(dataser => {
      console.log('dggd', dataser);
      expect(dataser[1].name).toEqual('High1');
    });

    const req = httpTestingController.expectOne(Constants.SERVER_URL + '/customeType/getPropertyList/' + '193');
expect(req.request.url).toEqual(Constants.SERVER_URL + '/customeType/getPropertyList/' + '193');
  });

          and this is my service file which i am going to test
getPropertyList(propertyTypeId) {
        this.token = localStorage.getItem('token');
        this.headers = new Headers();
        // this.headers.delete(this.token);
        this.headers.append('Authorization', this.token);
        return this._http.get(Constants.SERVER_URL + '/customeType/getPropertyList/' +
        propertyTypeId, { headers: this.headers }).pipe(map(data => data.json()));
    }


================================================================

this is my method to communicate with service.

getPropertyList(propertyTypeId) {
        this.token = localStorage.getItem('token');
        this.headers = new Headers();
        // this.headers.delete(this.token);
        this.headers.append('Authorization', this.token);
        return this._http.get(Constants.SERVER_URL + '/customeType/getPropertyList/' +
        propertyTypeId, { headers: this.headers }).pipe(map(data => data.json()));

Error: Expected one matching request for criteria "Match URL: http://192.168.1.222:8080/customeType/getPropertyList/193", found none.

Можете ли вы помочь мне, где ошибка в моем коде?

...