No provider for NgControl found in NodeInjector

If you are getting the following error while running ng test:

Failed: NG0201: No provider for NgControl found in NodeInjector.

the solution is to import ReactiveFormsModule in your spec file of your component


  beforeEach(async () => {
    await TestBed.configureTestingModule({
      imports:[FormsModule]
    }).compileComponents();

The full file will look like this:

import { ComponentFixture, TestBed } from '@angular/core/testing';
import { FormsModule } from '@angular/forms';

import { YourComponent } from './YourComponent.component';

describe('YourComponent', () => {
  let component: YourComponent;
  let fixture: ComponentFixture<YourComponent>;

  beforeEach(async () => {
    await TestBed.configureTestingModule({
      imports:[FormsModule],
      declarations:[....YourDeclarationsIfNeeded]
    }).compileComponents();

    fixture = TestBed.createComponent(YourComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

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