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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值