gpt4 book ai didi

Angular CLI Jasmine 单元测试错误 : Can't resolve all parameters for RequestOptions: (? )

转载 作者:行者123 更新时间:2023-12-03 14:35:31 31 4
gpt4 key购买 nike

首先我得到了这个错误 ConnectionBackend 没有提供者!所以我将它导入到我的规范中虽然我没有在我的服务中导入它

然后我没有 RequestOptions 的提供者!我也将它导入到我的规范中,虽然我没有在我的服务中导入它

然后我收到此错误:无法解析 RequestOptions 的所有参数:(?)。

有什么建议吗?

预订数据服务规范

import { TestBed, inject } from '@angular/core/testing';
import { BookingDataService } from './booking-data.service';
import { Http, ConnectionBackend, RequestOptions } from '@angular/http';

describe('BookingDataService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [BookingDataService, Http, ConnectionBackend, RequestOptions]
});
});

it('should be created', inject([BookingDataService], (service: BookingDataService) => {
expect(service).toBeTruthy();
}));
});

应用组件规范

import { TestBed, async } from '@angular/core/testing';

import { FormGroup, ReactiveFormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';

import { AppComponent } from './app.component';
import { FindTripComponent } from './find-trip/find-trip.component';

describe('AppComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
ReactiveFormsModule,
HttpModule
],
declarations: [
AppComponent,
FindTripComponent
]
}).compileComponents();
}));

it('should create the app', async(() => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
}));

});

预订数据服务

import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map'

@Injectable()
export class BookingDataService {

//create instance of http
constructor(private _http: Http) { }

//get data from json file
fetchData() {
return this._http.get('/assets/mockdata/mock.json').map(
response => response.json()
);
}

}

最佳答案

在您的 BookingDataService 规范 文件中,

修改TestBed.configuration

  • 删除提供者 Http、RequestOptions
  • 导入 HttpModule

关于Angular CLI Jasmine 单元测试错误 : Can't resolve all parameters for RequestOptions: (? ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44615964/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com