【发布时间】:2021-04-17 02:23:21
【问题描述】:
我收到以下错误:..
Can't resolve all parameters for Service1: (?, ?).
Service1.ts
export class Service1 {
constructor(protected url: string, protected http: HttpClient) { }
}
Service1.spec.ts
describe('Service1', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
providers: [Service1],
});
});
it('should be created', () => {
const service1: Service1 = TestBed.get(Service1);
expect(service1).toBeTruthy();
});
});
在这里只模拟了 httpclient 模块,如果它模拟 url:stirng 部分它会起作用,我想是的。那么我怎样才能模拟和 makke 测试通过?。
【问题讨论】:
-
您正在尝试将
url字符串注入服务。 Angular 无法知道应该在此处注入哪个 url,因此这在测试和应用程序本身中都应该失败。
标签: angular unit-testing jestjs