Skip to content

Instantly share code, notes, and snippets.

@CHBaker
Last active February 8, 2018 16:27
Show Gist options
  • Save CHBaker/fe81b911c52bb68a6edb718192f08357 to your computer and use it in GitHub Desktop.
Save CHBaker/fe81b911c52bb68a6edb718192f08357 to your computer and use it in GitHub Desktop.
Dynamically pass a FormGroup to a child component in a Karma test (Angular)
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ReactiveFormsModule, FormBuilder } from '@angular/forms';
import { CommonModule } from '@angular/common';
import { AppModule } from './app.module';
import { ChildComponent } from './child.component';
describe('StaticComponent', () => {
let component: StaticComponent;
let fixture: ComponentFixture<ChildComponent>;
beforeEach(
async(() => {
TestBed.configureTestingModule({
declarations: [
ChildComponent
],
imports: [
CommonModule,
ReactiveFormsModule,
AppModule
]
}).compileComponents();
})
);
beforeEach(() => {
fixture = TestBed.createComponent(ChildComponent);
component = fixture.componentInstance;
// error occurs at 36
fixture.detectChanges();
});
it('should be created', () => {
expect(component).toBeTruthy();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment