在Angular for Protractor测试方案中使用http请求模拟特定方法

时间:2019-11-17 13:46:07

标签: angular protractor httprequest angular-test

我知道这个问题已经问过很多遍了,但是对于这种特定情况,我似乎找不到正确的方法来模拟后端。我正在尝试对e2e testing做一些protractor,对于大多数测试方案,我需要先登录。但是我不想依赖后端,所以我正在寻找一种模拟它的方法。我看到的大多数示例中,方法都返回一个Promise,并且它们在spec文件中对其进行预订,但是这里的预订是在该方法内部完成的。

这是我谈论的方法类型:

private logInExistingUser() {
    const postData = new FormData();
    postData.append('username' , this.username);
    postData.append('password' , this.pwd);

    this.http
      .post('go/login', postData, {withCredentials: true})
      .subscribe(() => this.getProfile());
  }

那么如何在不依赖后端的情况下在e2e testing中进行登录?

任何帮助将不胜感激。

0 个答案:

没有答案