Currently, I am facing an issue where the automatic generation of spec.ts files has been disabled by the developers when they created the components. To address this, I manually created the spec.ts files by copying over an existing one into each component, with the only difference being the name of the component.
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { NavMenuComponent } from './nav-menu.component';
describe('NavMenuComponent', () => {
let component: NavMenuComponent;
let fixture: ComponentFixture<NavMenuComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ NavMenuComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(NavMenuComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
Upon running 'npm run test', the tests failed for nearly every component. I suspect that there may be additional steps required beyond just creating the spec.ts file and adding the code above. The error message generated by npm run test is quite lengthy and seems to indicate that I am importing something that does not exist, but I am unsure how to resolve this issue:
Chrome 85.0.4183.121 (Mac OS 10.15.7) SelectiveComponent should create FAILED
NullInjectorError: R3InjectorError(DynamicTestModule)[SearchService -> HttpClient -> HttpClient]:
NullInjectorError: No provider for HttpClient!
error properties: Object({ ngTempTokenPath: null, ngTokenPath: [ 'SearchService', 'HttpClient', 'HttpClient' ] })
NullInjectorError: R3InjectorError(DynamicTestModule)[SearchService -> HttpClient -> HttpClient]:
NullInjectorError: No provider for HttpClient!
at NullInjector.get (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:915:1)
at R3Injector.get (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:11076:1)
...
If anyone has insights or suggestions on how to resolve this issue, any help would be greatly appreciated!