Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NicholasMurray/1bc6320fdda7bb43fac838e0b5cb0885 to your computer and use it in GitHub Desktop.
Save NicholasMurray/1bc6320fdda7bb43fac838e0b5cb0885 to your computer and use it in GitHub Desktop.
first-reactive-form spec
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