i'm new with angular testing and i'm trying to test if mocked json is equal to json in db.json. The problem is that the tests have succes even if json server is down. Here my spec:
import { TestBed } from '@angular/core/testing';
import { ProfileService } from './profile.service';
import { HttpClientTestingModule,
HttpTestingController } from '@angular/common/http/testing';
describe('ProfileService', () => {
// We declare the variables that we'll use for the Test Controller and for our Service
let httpTestingController: HttpTestingController;
let service: ProfileService;
beforeEach(() => {
TestBed.configureTestingModule({
providers: [ProfileService],
imports: [HttpClientTestingModule]
});
// We inject our service (which imports the HttpClient) and the Test Controller
httpTestingController = TestBed.get(HttpTestingController);
service = TestBed.get(ProfileService);
});
afterEach(() => {
httpTestingController.verify();
});
describe('#getInfoContratto', () => {
let expectedInfo = JSON.parse('{"abi": "string","banca": "string", "cab": "string","cin": "string","codiceRID": "string","conto": "string", "dataAllineamento": "string","dataAttivazione": "string","dataUltimaModifica": "string","iban": "string","intestatarioConto": "string","nome": "string","societa": "string","sportello": "string","stato": "string","statoAllineamento": "string","tipoGaranzia": "string","valoreDellaFidejussione": "string"}');
it('should return expected info', () => {
service.getInfoContratto("TEST").subscribe(
infoContratti => expect(infoContratti).toEqual(expectedInfo, 'should return expected info'),
fail
);
const req = httpTestingController.expectOne({ method: 'POST', url: service.serverUrl+ "accesso-utenti-infoContratto" });
// expect(req.request.method).toEqual('POST');
req.flush(expectedInfo);
console.log(req.request.url);
});
});
What i'm doing wrong?