小编N.T*_*N.T的帖子

使用 flush() 方法时:“响应类型不支持自动转换为 JSON。”

当我使用flush()测试 HTTP 请求的方法时,出现此错误:

响应类型不支持自动转换为 JSON。

你能不能解释一下flush()方法的目标。我真的不明白。

问题并没有真正解决。我们必须像这样向“it”函数添加 async() 方法:“it('should get the post', async(() => {

import { TestBed } from '@angular/core/testing';
import {HttpClientTestingModule, HttpTestingController} from "@angular/common/http/testing"
import { DataService } from './data.service';
import { Observable } from 'rxjs';
import { Post } from './post.model';
import { HttpClientModule } from '@angular/common/http';

describe('DataService', () => {

  let service: DataService
  let  httpTestingController: HttpTestingController
  let attemptedPost : Post;
  const post = {
    userId: 1,
    id: 1,
    title: "sunt aut facere repellat provident …
Run Code Online (Sandbox Code Playgroud)

unit-testing angular

7
推荐指数
1
解决办法
5361
查看次数

标签 统计

angular ×1

unit-testing ×1