Angular 11 -测试用例编写- Jasmine -弃用问题



我正在尝试使用Jasmine创建我的第一个测试用例,这是我第一次尝试编写测试用例(实际上刚刚开始学习)。我目前正在参考这个站点编写测试用例

我现在面临两个问题。

  1. 签名'(令牌:any, notFoundValue?: any):任意' of 'TestBed。Get '已弃用。ts(6387)testing.d。ts(382,9):声明在这里被标记为deprecated。TestBedStatic(方法)。get(token: any, notFoundValue?): any): any (+1 overload)

  2. 类型'(typeof EmployeeService)[]'的参数不能赋值给类型' type | AbstractType | InjectionToken'的参数。类型'(typeof EmployeeService)[]'缺少类型'AbstractType'的以下属性:prototype, apply, call, bind, and more.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;
}

testcase

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

谢谢所有的

TestBed.get已弃用,参见此答案。从Angular 9开始,用TestBed.inject代替TestBed.get

最新更新