Skip to content

Instantly share code, notes, and snippets.

@Teebo
Created January 31, 2021 12:27
Show Gist options
  • Save Teebo/a02d31642211b77daa87b15068b93709 to your computer and use it in GitHub Desktop.
Save Teebo/a02d31642211b77daa87b15068b93709 to your computer and use it in GitHub Desktop.
Unit test for @ViewChild approach
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { FormBuilder, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HobbiesStubComponent } from './component-stubs/hobbies-stub.component';
import { HeroComponent } from './hero.component';
describe('HeroComponent', () => {
let component: HeroComponent;
let fixture: ComponentFixture<HeroComponent>;
const formBuilder: FormBuilder = new FormBuilder();
const powersComponent = jasmine.createSpyObj('PowersComponent', ['createFormGroup']);
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [HeroComponent, HobbiesStubComponent],
providers: [{ provide: FormBuilder, useValue: formBuilder }],
imports: [FormsModule, ReactiveFormsModule]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(HeroComponent);
component = fixture.componentInstance;
component.powersComponent = powersComponent;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment