Contenido del curso
Testing helpers
Pruebas a Fields
Pruebas a Forms
Pruebas a Validadores
Continua aplicando testing con Angular
Pruebas a validadores
Contenido del curso
Pruebas a validadores
Ana Velez Ossa
EstudianteRoberto Bock
EstudianteCódigo de la prueba:
import { FormControl, FormGroup } from "@angular/forms"; import { MyValidators } from "./validators"; fdescribe('test fot MyValidators', () => { describe('test fot validPassword', () => { it('should return null when password is right', () => { const control = new FormControl(); control.setValue('ana123'); const rta = MyValidators.validPassword(control); expect(rta).toBeNull() }) it('should return null when password is wrong', () => { const control = new FormControl(); control.setValue('asasasas'); const rta = MyValidators.validPassword(control); expect(rta?.invalid_password).toBeTrue() }) }); describe('test for matchPasswords', () => { it('should return null', () => { const group = new FormGroup({ password: new FormControl('123456'), confirmPassword: new FormControl('123456') }); const rta = MyValidators.matchPasswords(group); expect(rta).toBeNull(); }); it('should return obj with the error', () => { const group = new FormGroup({ password: new FormControl('123456'), confirmPassword: new FormControl('123a456') }); const rta = MyValidators.matchPasswords(group); expect(rta?.match_password).toBeTrue(); }); it('should error with send other data', () => { const group = new FormGroup({ opt: new FormControl('123456'), opt2: new FormControl('123a456') }); const fn = () => { MyValidators.matchPasswords(group) } expect(fn).toThrow(new Error('matchPasswords: fields not found')); }); }); })
honestamente al final de esta clase sentí que el profe ya se "ostinó" de dar clases de angular XD pero lo quiero igual!