For this you have to import the following:
import { HttpClientTestingModule } from '@angular/common/http/testing';
And for the spec file in the configureTestingModule of your test, do the following:
TestBed.configureTestingModule({
imports: [ HttpClientTestingModule ],
})
.compileComponents();