当我使用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)