i am new to angular testing using Jasmine/Karma , i encoutered a problem while testing an angular service using HttpTestingController . here is a part of the source code :
getProfile(userName: string) {
let config = {
params: {
user_id: "test"
}
}
return this.http
.get(`https://api.github.com/users/${userName}`, config);
}
when calling the service using expectOne of HttpTestingController :
it('should add an Authorization header', () => {
let response;
userService.getProfile('blacksonic').subscribe(response => {
expect(response).toBeTruthy();
});
const req =
httpMock.expectOne({ method: 'GET', url:'https://api.github.com/users/blacksonic' });
});
i get the following error :
Error: Expected one matching request for criteria "Match method: GET, URL: https://api.github.com/users/blacksonic", found none. at HttpClientTestingBackend.expectOne (./node_modules/@angular/common/fesm5/http/testing.js?:301:19) at UserContext.eval (./src/app/Interceptors/Interceptor.spec.ts?:85:28) at ZoneDelegate.invoke (./node_modules/zone.js/dist/zone.js?:387:26) at ProxyZoneSpec.onInvoke (./node_modules/zone.js/dist/zone-testing.js?:287:39) at ZoneDelegate.invoke (./node_modules/zone.js/dist/zone.js?:386:32) at Zone.run (./node_modules/zone.js/dist/zone.js?:137:43) at runInTestZone (./node_modules/zone.js/dist/zone-testing.js?:508:34) at UserContext.eval (./node_modules/zone.js/dist/zone-testing.js?:523:20)
Aucun commentaire:
Enregistrer un commentaire