Angular测试遇到的小坑

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的简单封装。

 

转载于:https://www.cnblogs.com/yoyogis/p/9215052.html


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部