1
TestBed.configureTestingModule({
    imports: [
        FormsModule,
        ReactiveFormsModule,
    ]
});

TestBed.get(FormBuilder);

What do I need to do? Or I should just use new operator to create one?

tom10271
  • 4,222
  • 5
  • 33
  • 62

1 Answers1

1

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.

Estus Flask
  • 206,104
  • 70
  • 425
  • 565