Total novice at Karma/Jasmine looking for some assistance. I'm trying to run the following test and I get the error "Cannot make XHRs within a fake async test". I have included the test and the method I am attempting to call. Any help is greatly appreciated.
import...
fdescribe('CageService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
RouterTestingModule,
HttpModule
],
providers: [
BaseRequestOptions,
MockBackend,
CageService,
{ provide: 'appHttpService', useClass: AppHttpService },
{ provide: 'appHttpHelperService', useClass: AppHttpHelperService },
{ provide: 'appUtilityService', useClass: AppUtilityService },
{ provide: Http, useFactory: (backend: ConnectionBackend, defaultOptions: BaseRequestOptions) => {
return new Http(backend, defaultOptions);
}, deps: [MockBackend, BaseRequestOptions] }
]
});
});
it('will load cages', inject([CageService, MockBackend], fakeAsync(( cageService, mockBackend\) => {
var res;
mockBackend.connections.subscribe( c => {
expect(c.request.url).toBe('http://example.com');
let response = new ResponseOptions( { body: '{"name": "charles"}' } );
c.mockRespond( new Response( response ) );
});
cageService.load({}).subscribe((_res) => {
res = _res;
});
tick(100);
discardPeriodicTasks();
expect(res.name).toBe('Charles');
})));
});
The method I am calling reads
load ( criteria: Object ) {
return this.appHttpService.get( this.url + '?' + criteria )
.map(
response => {
let data = response.json();
this.pagination.total = data.count;
this.pagination.per_page = data.limit;
this.pagination.current_page = data.currentPage;
this.pagination.last_page = data.totalPages;
let cages = [];
for( let x = 0; x < data.rows.length; x++ ) {
cages.push( this.formatCage(new Cage(), data.rows[x] ) );
}
this._cages$.next( this.dataStore.cages );
return data.rows;
}
);
}