Created
January 31, 2021 12:27
-
-
Save Teebo/a02d31642211b77daa87b15068b93709 to your computer and use it in GitHub Desktop.
Unit test for @ViewChild approach
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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