How to mock a service which has http requests?
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 25/100
- Loại issue
- Tài liệu
- Độ rõ ràng
- Cần làm rõ
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- typescript
- Lĩnh vực
- api, testing-qa
Hướng nghiên cứu
Issue này nêu tên service.ts và service.spec.ts, đồng thời tập trung vào việc getGoogle() gọi http.get(). Hãy bắt đầu bằng cách xem xét thiết lập Karma và Jasmine của repository cũng như cấu hình kiểm thử hiện có. Công việc được xem là hoàn tất khi có một cách được lập tài liệu và có thể tái lập để kiểm thử phương thức mà không phụ thuộc vào request trực tiếp.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Hey,
I know this is not the right platform to ask this, but on right platform, there is no reply from anyone.
How to mock a service which contains http requests?
For eg:
I want to test my provider class, so I am unable to write spec for providers.
My provider is as follows:
service.ts
//imports are done correctly.
@Injectable()
export class Service {
constructor(private http: Http) { }
getGoogle():Observable<any> {
console.log("Inside service");
return this.http.get('https://jsonplaceholder.typicode.com/posts/1');
} }
My page.ts is as follows:
page.ts
**//imports are done correctly.
export class Page1 {
constructor(private service: Service, private navCtrl: NavController) { }
async get() { console.log("inside get method");
const data = await this.service.getGoogle().toPromise();
console.log('The response is' , data);
} }
service.spec.ts
//imports are done correctly
describe('Service', () =>
{ let comp: Service;
let fixture: ComponentFixture<Service>;
let de: DebugElement;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [],
imports: [
IonicModule.forRoot(Service)
],
providers: [Http]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(Service);
comp = fixture.componentInstance;
de = fixture.debugElement;
});
afterEach(() => {
fixture.destroy();
});
it('test the http request to te server', ()=>{
//code to test http request of the Service class });
});**
All the imports are done correctly, only the logic to test the getGoogle() with http.get() needs to be tested.Please help or share some links or tell me some steps in order to do testing of this ionic2 content.
Thanks
Adi
- Ngôn ngữ chính
- TypeScript
- Star
- 370
- Fork
- 144
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của ionic-team/ionic-unit-testing-example
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 35/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 20/100
-
Error output is minified Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 20/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
ionic-team/ionic-unit-testing-example#91 · 7 bình luận · 11 reaction ·
Tất cả issue của ionic-team/ionic-unit-testing-example
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
mksglu/context-mode#1200 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
jaegertracing/jaeger-ui#4506 ·
-
area:desktop area:ui bug platform:macos
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
anthropics/claude-code#96687 ·
-
good first issue
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 95/100
AOSSIE-Org/DebateAI#582 · 2 bình luận ·