I'm trying my hand at creating an Angular unit test, but failing right off the bat.
I've taken a look at this and this this SO, which seems to be exactly what I'm struggling with, but after attempting the fixes mentioned there, I am still not coming right.
This is my code :
import { TestBed } from '@angular/core/testing';
import { ContactsService } from './contacts.service';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { HttpClient } from '@angular/common/http';
describe('ContactsService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [ HttpClientTestingModule, ContactsService, HttpClient],
})
.compileComponents();
});
});
When I run an ng test, I get this error :
NullInjectorError: R3InjectorError(DynamicTestModule)[ContactsService -> HttpClient -> HttpClient]: NullInjectorError: No provider for HttpClient!
My .ts, for completeness :
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Entry } from '../classes/entry';
import { EntrySearch } from '../classes/entrySearch';
@Injectable({
providedIn: 'root'
})
export class ContactsService {
constructor(private http: HttpClient) { }
}