AngularCli - 为什么我在 JSON 测试期间收到语法错误?



我试图测试一个组件,当在浏览器环境中使用时,它正是我想要的。组件的主要方法是:

login(auth: Credential): Observable<Access>     {
  const options = new RequestOptions({headers: this.headers});
  const json = JSON.stringify(auth);
  return this.http.post(this.authUrl, json, options)
    .map((res: Response) => {
      return res.json().token() || {};
    }).catch(error => {
      console.log(error);
      if(error.status == 401) {
        return Observable.throw('Usuário ou senha inválidos!');
    }});
  }
}

我不明白的是为什么当我运行ng test时,console.log说:SyntaxError{},当我通过普通浏览器运行此代码时,它只是说这是正常的httperror。

JSON>stringify(auth);

您有>而不是.

最新更新