5
내 ng2 서비스를 테스트하기 위해 ng2-restangular를 조롱하는 올바른 방법을 찾으려고합니다. 서비스 방법에 대한 예를 들어ng2 단위 테스트를 위해 ng2-restangular를 조롱하는 방법?
:
get(id) {
return this.restangular.all('notes').get(id);
}
내 ng2 서비스를 테스트하기 위해 ng2-restangular를 조롱하는 올바른 방법을 찾으려고합니다. 서비스 방법에 대한 예를 들어ng2 단위 테스트를 위해 ng2-restangular를 조롱하는 방법?
:
get(id) {
return this.restangular.all('notes').get(id);
}
링크 : https://github.com/2muchcoffeecom/ng2-restangular/blob/master/demo/mock-data/mock-providers.ts
import {BaseRequestOptions, Http} from "@angular/http";
import {MockBackend} from "@angular/http/testing";
import {RestangularHttp} from "../../src/ng2-restangular-http";
export const MockProviders = [
BaseRequestOptions,
MockBackend,
{
provide: RestangularHttp,
useFactory: (http: Http) => {
return new RestangularHttp(http);
},
deps: [Http]
},
{
provide: Http,
useFactory: (backendInstance: MockBackend, defaultOptions: BaseRequestOptions) => {
return new Http(backendInstance, defaultOptions);
},
deps: [MockBackend, BaseRequestOptions]
},
];
이 질문에 대답 할 수 있지만, 간단한 설명을 –
감사 Tonyo를 추가하는 것이 좋습니다! 더 나은 조사를위한 좋은 지적 –