Error: Expected no open requests, found 1

Discussão em 'Angular' iniciado por user1037747, Dezembro 19, 2024.

  1. user1037747

    user1037747 Guest

    I am getting this error when I try to execute HTTP unit test cases.

    I am using Angular 5. How can I resolve this?

    Below is my code for normal GET. Below code just brings normal GET.

    import { TestBed } from '@angular/core/testing';
    import { HttpClientTestingModule, HttpTestingController, TestRequest } from
    '@angular/common/http/testing';

    import { DangerService } from './danger.service';
    import { DangerFlag } from '../danger.model';


    describe('DataService Tests', () => {
    let dataService: DangerService;
    let httpTestingController: HttpTestingController;

    let testDangerFlags: DangerFlag[] = [ "sample data" ]

    beforeEach(() => {
    TestBed.configureTestingModule({
    imports: [ HttpClientTestingModule ],
    providers: [ DangerService ]
    });

    dataService = TestBed.get(DangerService);
    httpTestingController = TestBed.get(HttpTestingController);
    });

    afterEach(() => {
    httpTestingController.verify();
    });

    fit('should get all danger flags', () => {
    dataService.getDangerFlagDetails()
    .subscribe((data: DangerFlag[]) => {
    expect(data.length).toBe(3);
    });
    });
    });

    Continue reading...

Compartilhe esta Página