1 pièce(s) jointe(s)
Consommer mon api avec les test unitaire
Bonjour,
j'ai une consommation de webservice qui me donner un json:
Pièce jointe 553385
le web service me donner ce json:
voici la méthode qui demande la requête get:
Code:
1 2 3 4 5 6 7 8 9 10 11
|
getBouchon(url) {
this.http.get(url).subscribe(data =>{
console.log(data);
return data;
},error =>{
console.log(error);
});
} |
Mon but est d'écrire un test unitaire qui test cette valuer, la voici:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
let laRacine = window.location.hostname;
import { async, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { NavigationService } from 'src/services/navigation.service';
import { HttpClientTestingModule } from '@angular/common/http/testing';
describe('FormUpldComponent', () => {
let wbsSQL;//chemain webservice
let navigationService;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [RouterTestingModule, HttpClientTestingModule],
declarations: [],
providers: [NavigationService, RouterTestingModule]
}).compileComponents();
navigationService = TestBed.get(NavigationService);
wbsSQL = laRacine + navigationService.hostPortSQL;
});
it('test du chargement du fichier avec formaData', async(() => {
let url = wbsSQL + "/bouchon?ladateClient=18h08";
let dateClientServ = navigationService.getBouchon(url);
console.log(dateClientServ);
expect(dateClientServ).toEqual('{client: "wbsok"}');
}));
}); |
quand je lance ng test, j'ai cette erreur:
du côté backend il n'y aucune demande de requête .
Comment fait t'on pour consommer la requête ?
en mode ng serve, la méthode getBouchon() fonctionne bien.
si vous avez une idée, merci d'avance pour la réponse.