TestBed.configureTestingModule({
imports: [
FormsModule,
ReactiveFormsModule,
]
});
TestBed.get(FormBuilder);
What do I need to do? Or I should just use new operator to create one?
TestBed.configureTestingModule({
imports: [
FormsModule,
ReactiveFormsModule,
]
});
TestBed.get(FormBuilder);
What do I need to do? Or I should just use new operator to create one?
No, you can:
describe('FormBuilder', () => {
let fb;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
ReactiveFormsModule
]
});
fb = TestBed.get(FormBuilder);
});
it('should be FormBuilder instance', () => {
expect(fb instanceof FormBuilder).toBe(true);
});
});
As explained here, TestBed.get
is same thing as inject
helper, it creates an injector on first call and gets provider instance.
FormsModule
and ReactiveFormsModule
are mutually exclusive and aren't supposed to be used together, but this shouldn't affect the result.