Angular测试遇到的小坑
Error: Expected to be running in 'ProxyZone', but it was not found
检查doneFn的写法是否正确,位置是否正确,是否定义为undefined
Unhandled Promise rejection: 'expect' was used when there was no current spec - Google Search
检查donfFn或者asyn是否使用正确,如果是测试异步方法,expect方法是否包含在asyn或者有donfFn的函数里面
fail() 调用了,但是却pass了
检查console中是否有异常
dondFn的用法
done(): 执行这个表示成功
done.fail(err): 执行这个表示失败,参数可以是异常err或者文本
beforeAll((done:DoneFn)=>{
TestBed.configureTestingModule({
imports: [HttpClientModule],
providers: [ProjectResourceService]
});
})
beforeAll((done:DoneFn)=>{
TestBed.configureTestingModule({
imports: [HttpClientModule]
});
http = TestBed.get(HttpClient);
auth(http).then(()=>{
done();
});
});
beforeAll中配置TestBed.configureTestingModule报错:Error: Cannot configure the test module when the test module has already been instantiated. Make sure you are not using `inject` before
目前还没搞清楚,我在的问题是将HttpClientModule在beforeAll中导入就会报这个错。我的解决办法是不用HttpClient,从网上找了个xhr的简单封装。