Error when unit testing: “Uncaught (in promise) SyntaxError: Unexpected token o in JSON at position 1”

后端 未结 4 1226
太阳男子
太阳男子 2020-12-10 16:58

I\'d like to unit test a service, however, when running the test, I get the following error:

Uncaught (in promise) SyntaxError: Unexpected token o in

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-10 17:46

    As it turned out I missed the import for Response:

    Before: import { BaseRequestOptions, Http, ResponseOptions } from '@angular/http';

    After: import { BaseRequestOptions, Http, Response, ResponseOptions } from '@angular/http';

    Without importing Response from @angular/http, Response defaults to ECMAScript APIs.

提交回复
热议问题