Test d'unité angulaire: Résultats observables de ne pas retourner
const MOCK_GET_URL_RESPONSE = 'test';
export class MockService() {
// Implement service functions here
getUrl(): Observable<any> {
return of(MOCK_GET_URL_RESPONSE);
}
}
describe('ABCComponent', () => {
let component: ABCComponent;
let fixture: ComponentFixture<ABCComponent>;
let service: MockService;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ABCComponent],
imports: [CommonModule, HttpClientTestingModule],
// Provide your service and indicate which
// class is to be used to mock it
providers: [{ provide: MyService, useClass: MockService }],
}).compileComponents();
});
it('should create', () => {
service.getUrl().subscribe((res) => {
console.log(res); // test
expect(res).not.toBeNull(); // true
});
});
});
SAMER SAEID