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

Testing search service => DONE

parent 43226e70
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 { SearchService } from './search.service';
import { AppConfigService } from 'src/app/app-config.service';
describe('SearchService', () => {
let service: SearchService;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
providers: [
{ provide: AppConfigService, useValue: { apiUrl: 'http://testing.com' } },
SearchService
]
});
service = TestBed.inject(SearchService);
});
it('#retrieveData() should return an Observable<any[]>',
inject([HttpTestingController, SearchService],(httpMock: HttpTestingController, searchService: SearchService) => {
const mockResponse = ['myData'];
searchService.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