Skip to content
Snippets Groups Projects
Commit da04b124 authored by Tifenn Guillas's avatar Tifenn Guillas
Browse files

WIP: Testing on detail service

parent c1e7655e
No related branches found
No related tags found
2 merge requests!29Develop,!8Resolve "Add tests for instance store module"
import { TestBed, inject } from '@angular/core/testing';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { DetailService } from './detail.service';
import { AppConfigService } from 'src/app/app-config.service';
describe('DetailService', () => {
let service: DetailService;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
providers: [
{ provide: AppConfigService, useValue: { apiUrl: 'http://testing.com' } },
DetailService
]
});
service = TestBed.inject(DetailService);
});
it('#retrieveData() should return an Observable<any[]>',
inject([HttpTestingController, DetailService],(httpMock: HttpTestingController, detailervice: DetailService) => {
const mockResponse = ['myData'];
detailervice.retrieveData('myQuery').subscribe((event: any[]) => {
expect(event).toEqual(mockResponse);
});
const mockRequest = httpMock.expectOne('http://testing.com/search/myQuery');
expect(mockRequest.cancelled).toBeFalsy();
expect(mockRequest.request.responseType).toEqual('json');
mockRequest.flush(mockResponse);
httpMock.verify();
}
)
);
// it('#retrieveDataLength() should return an Observable<{ nb: number }[]>',
// inject([HttpTestingController, SearchService],(httpMock: HttpTestingController, searchService: SearchService) => {
// const mockResponse = [{ nb: 1 }];
//
// searchService.retrieveDataLength('myQuery').subscribe((event: { nb: number }[]) => {
// expect(event).toEqual(mockResponse);
// });
//
// const mockRequest = httpMock.expectOne('http://testing.com/search/myQuery');
//
// expect(mockRequest.cancelled).toBeFalsy();
// expect(mockRequest.request.responseType).toEqual('json');
// mockRequest.flush(mockResponse);
//
// httpMock.verify();
// }
// )
// );
});
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment