1

I have the following code,

** component.ts,

 constructor(public cdr:ChangeDetectorRef, public fb:FormBuilder) { 
   this.buildForm();
 }



buildForm(): void {
 this.feedbackForm = this.fb.group({
  suggestedAScore: ['', [Validators.pattern(/^[0-9]+$/),Validators.required, Validators.maxLength(5), Validators.minLength(5)]],
  minScore: ['', [Validators.pattern(/^[0-9]+$/),Validators.required,Validators.minLength(1),Validators.maxLength(1)]],
  maxScore: ['', [Validators.pattern(/^[0-9]+$/),Validators.required,Validators.minLength(1),Validators.maxLength(1)]]
});
 this.feedbackForm.setValidators(this.minMaxValidator());
this.isFeedbackFormValid();
};

** spec.ts, (shallow render)

 describe('FeedbackOptionsComponent', () => {
  let shallow: Shallow<FeedbackOptionsComponent>;

 beforeEach(() => {
   shallow = new Shallow(FeedbackOptionsComponent, AnnualCompensationModule)
   .provide(FormBuilder)
 });

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

When I run the code I am getting the test case,I am getting the following error:

this.fb.group({ is not a function

I am new to unit test cases.Can anyone please suggest me help to resolve this.

learner
  • 357
  • 1
  • 6
  • 16

1 Answers1

0

You can use neverMock to init FormGroup module

import { FormsModule} from '@angular/forms';

 describe('FeedbackOptionsComponent', () => {

 Shallow.neverMock(FormsModule);

   beforeEach(() => {
   shallow = new Shallow(FeedbackOptionsComponent, AnnualCompensationModule);
 });

  });
 
Chunbin Li
  • 2,196
  • 1
  • 17
  • 31