1

I'm trying to test a component that has imported 'FormGroup' and 'FormBuilder', but when I'm trying to run the test file for that component it gives me an error saying 'FormGroup' and 'FormBuilder' isn't a known property of form. I tried doing something like this,

TestBed.configureTestingModule({
imports: [ ],
declarations: [ FormComponent ],
providers: [ FormGroup, FormBuilder ]
})

but then it gives the following error:

Uncaught Failed: Can't resolve all parameters for FormGroup: (?, ?, ?).
Error: Can't resolve all parameters for FormGroup: (?, ?, ?).

So how can I import formgroup and formbuilder in the testing (spec) file?

Angular Version I'm using: 2.1.0

Aiguo
  • 3,416
  • 7
  • 27
  • 52

1 Answers1

2

it gives me an error saying 'FormGroup' and 'FormBuilder' isn't a known property of form.

The same way you imported ReactiveFormsModule into your application module(s), you need to do the same in the testing module

TestBed.configureTestingModule({
  imports: [ ReactiveFormsModule ],
  declarations: [ FormComponent ]
})
Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720