【发布时间】:2021-08-02 11:40:05
【问题描述】:
我正在尝试使用 Jasmine 创建我的第一个测试用例,这是我第一次尝试编写测试用例(实际上刚刚开始学习)。我目前正在参考This site 编写测试用例
这里我面临两个问题。
-
'TestBed.get' 的签名 '(token: any, notFoundValue?: any): any' 已弃用.ts(6387) testing.d.ts(382, 9):声明在此处被标记为已弃用。 (方法) TestBedStatic.get(token: any, notFoundValue?: any): any (+1 重载)
-
'(typeof EmployeeService)[]' 类型的参数不能分配给 'Type | 类型的参数抽象类型 |注入令牌'。 类型“(typeof EmployeeService)[]”缺少类型“AbstractType”中的以下属性:prototype、apply、call、bind 和 4 多个.ts(2345)
员工模型
export interface Employee {
name: string;
desc: null | string;
action: string;
obj: Obj;
action: any;
}
export interface Obj {
empId: string;
empName: string;
reportTo: string;
country: string;
region: string;
empStatus: string;
department: string;
}
测试用例
describe('DataAccessService', () => {
let httpTestingController: HttpTestingController;
let dataAccessService: EmployeeService;
// let baseUrl = 'czm/getCustomerList';
let traveller: Employee;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule]
});
httpTestingController = TestBed.get(HttpTestingController);
traveller = {
name: 'Jane',
desc: 'Jane',
action: '',
obj: {
empId: 'Jane',
empName: 'Jane',
reportTo: 'TD1',
country: 'USA',
region: 'USA',
empStatus: 'Inactive',
department: 'HR - Marketing',
}
};
});
beforeEach(inject(
[EmployeeService],
(service: EmployeeService) => {
dataAccessService = service;
}
));
});
谁能告诉我如何解决这个问题?
如果可能,我请求一些 茉莉花专家 来创建 stackblitz
谢谢大家
【问题讨论】:
标签: angular unit-testing types jasmine karma-jasmine