我是这个角单元测试的新手,在测试上述标题的服务电话时遇到错误。为该问题提出一些解决方案。
**Service:**
// Add locale in particular store
addlocale(appLocale) {
return this.getJwt(this.adminToken).pipe(//Called jwt api
switchMap(data => {
this.authToken = data;
this.authToken1 = this.authToken.data.JWT;
let header = new HttpHeaders();
header = header.append('Authorization', this.authToken1);
header = header.append('Content-Type', 'application/json');
return this.http.post(this.url + 'locale/create/1', appLocale, { headers: header }); //HTtp call with header
}));
}
**Test case for the above service:**
it('Should post locale', () => {
const dummyParam = 1;
const locale: AppLocale[] = [
{locale_id: 10,
country: 'India',
language: 'Kan_In',
locale: 'Bng'
} ];
service.addlocale(locale).subscribe(response => {
console.log('Will come plz');
expect(response['data'].locale_id).toEqual('10');
//expect(response['data'].language).toEqual('Kan_In');
});
const req1 = http.expectOne('/test-env/v1/ezshopcart/JWT');
const req = http.expectOne('/test-env/v1/ezshopcart/locale/create/1');
//expect(req.request.method).toEqual('POST') && req.request.headers.get('Content-Type') === 'application/json' && req.request.headers.get('Authorization') === 'eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhdXRoMCJ9.93ijRbI37Czi8CW28R1aPNemFV7Qpfu1fNxtt75jxZWHBJQo5ex1NasASTm0y0o5CPygXD1tDYVMqvOFtfeZrg';
expect(req.request.method).toEqual('POST');
expect(req.cancelled).toBeFalsy();
expect(req.request.responseType).toEqual('json');
req.flush(locale);
req1.flush(locale);
});
得到这样的错误消息预期对标准“匹配URL:/ test-env / v1 / ezshopcart / locale / create / 1”的一个匹配请求,找不到。