Created
April 22, 2018 10:08
-
-
Save abner/df93f45f7ced67f3fd523001c7e751a7 to your computer and use it in GitHub Desktop.
form.spec.ts
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
// Teste Unitário de FormBuilder | |
import { Component } from '@angular/core'; | |
import { FormBuilder, FormGroup, Validators, ReactiveFormsModule, FormsModule } from '@angular/forms'; | |
import { async, TestBed } from '@angular/core/testing'; | |
describe('FormBuilder', () => { | |
/* @Component({ | |
selector: 'nao-usado', | |
template: '<form></form>' | |
}) | |
class ComponentWithForm { | |
constructor(formBuilder: FormBuilder) { | |
formBuilder.group({ | |
name: ['', Validators.required] | |
}) | |
} | |
} | |
*/ | |
/* | |
beforeEach(async(() => { | |
TestBed.configureTestingModule({ | |
imports: [ | |
FormsModule, | |
ReactiveFormsModule | |
], | |
declarations: [ | |
ComponentWithForm | |
], | |
}).compileComponents(); | |
})); | |
*/ | |
it('instatiate FormBuilder', () => { | |
let fb: FormBuilder = new FormBuilder(); | |
expect(fb).not.toBeNull(); | |
let form: FormGroup = fb.group({ | |
name: ['', Validators.required] | |
}); | |
expect(form.get('name').invalid).toBeTruthy(); | |
expect(form.invalid).toBeTruthy(); | |
form.get('name').setValue('abcde'); | |
expect(form.get('name').valid).toBeTruthy(); | |
expect(form.valid).toBeTruthy(); | |
form.get('name').setValue(''); | |
expect(form.get('name').invalid).toBeTruthy(); | |
expect(form.invalid).toBeTruthy(); | |
console.log(form.get('name').errors); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment