Created
January 4, 2018 16:00
-
-
Save NicholasMurray/1bc6320fdda7bb43fac838e0b5cb0885 to your computer and use it in GitHub Desktop.
first-reactive-form spec
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 { ReactiveFormsModule, FormsModule} from "@angular/forms"; | |
import { FirstReactiveFormComponent } from './first-reactive-form.component'; | |
describe('FirstReactiveFormComponent', () => { | |
let component: FirstReactiveFormComponent; | |
let fixture: ComponentFixture<FirstReactiveFormComponent>; | |
beforeEach(() => { | |
this.person = { | |
firstname: { | |
label: 'Firstname', | |
value: 'Nicholas', | |
type: 'text', | |
validators: { | |
required: true | |
} | |
}, | |
age: { | |
label: 'Age', | |
value: 45, | |
type: 'number', | |
validators: { | |
min: 18 | |
} | |
}, | |
gender: { | |
label: 'Gender', | |
value: 'M', | |
type: 'radio', | |
options: [ | |
{ label: 'Male', value: 'M' }, | |
{ label: 'Female', value: 'F' }, | |
] | |
}, | |
city: { | |
label: 'City', | |
value: 'SLC', | |
type: 'select', | |
options: [ | |
{ label: '(choose one)', value: '' }, | |
{ label: 'New York', value: 'NY' }, | |
{ label: 'Los Angeles', value: 'LA' }, | |
{ label: 'Salt Lake City', value: 'SLC' }, | |
] | |
} | |
}; | |
// refine the test module by declaring the test component | |
TestBed.configureTestingModule({ | |
imports: [ReactiveFormsModule, FormsModule], | |
declarations: [FirstReactiveFormComponent] | |
}); | |
// create component and test fixture | |
fixture = TestBed.createComponent(FirstReactiveFormComponent); | |
// get test component from the fixture | |
component = fixture.componentInstance; | |
component.formDataObj = this.person; | |
component.ngOnInit(); | |
}); | |
it('should create', () => { | |
expect(component).toBeTruthy(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment