1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

HttpTestingController runs endlessly

Discussão em 'Angular' iniciado por TalVik99, Novembro 30, 2025.

  1. TalVik99

    TalVik99 Guest

    In my component I have httpResource:

    export class EmployeesComponent {
    employees = httpResource<EmployeeResponseDtoOutput[]>(() => '/api/employees', {
    defaultValue: [],
    });
    }


    and in tests I try to test it with Vitest:

    describe('EmployeesComponent', () => {
    let component: EmployeesComponent;
    let fixture: ComponentFixture<EmployeesComponent>;
    let _httpTesting: HttpTestingController;

    beforeEach(async () => {
    await TestBed.configureTestingModule({
    imports: [EmployeesComponent],
    providers: [provideRouter([]), provideHttpClient(), provideHttpClientTesting()],
    }).compileComponents();

    fixture = TestBed.createComponent(EmployeesComponent);
    component = fixture.componentInstance;
    _httpTesting = TestBed.inject(HttpTestingController);
    await fixture.whenStable();
    });

    it('should create', () => {
    expect(component).toBeTruthy();
    });

    it('should fetch employees', () => {
    const req = _httpTesting.expectOne('/api/employees');
    expect(req.request.method).toBe('GET');
    req.flush([]);
    expect(component.employees).toEqual([]);
    _httpTesting.verify();
    });
    });


    For some reason, HttpTestingController causes tests to never finish. Even should create takes 30 seconds to timeout. When i remove HttpTestingController, should create completes normally. Why is this?

    Continue reading...

Compartilhe esta Página