- Instalaciones:
npm i --dev jest babel-jest @babel/preset-env @babel/preset-react
npm i --dev @testing-library/react @types/jest jest-environment-jsdom
- Opcional: Si usamos Fetch API en el proyecto:
| dateRangeValidator(field_1: string, field_2: string) { | |
| return (formGroup: AbstractControl): ValidationErrors | null => { | |
| let fromDate = formGroup.get(field_1)?.value; | |
| let toDate = formGroup.get(field_2)?.value; | |
| if(fromDate && toDate) { | |
| const newFromDate = new Date(fromDate); | |
| const newToDate = new Date(toDate); |
| containsURL(field: string) { | |
| return (formGroup: AbstractControl): ValidationErrors | null => { | |
| const text = formGroup.get(field)?.value; | |
| const match = text.match(this.urlPattern); | |
| if(text && match && match[0]) { | |
| formGroup.get(field)?.setErrors({includesURL: true}); | |
| return { includesURL: true }; | |
| }else if(!text) { | |
| formGroup.get(field)?.setErrors({required: true}); |
| export class AppComponent { | |
| value = 7; | |
| @HostListener("window:resize", []) updateValue() { | |
| // lg (for laptops and desktops - screens equal to or greater than 1200px wide) | |
| // md (for small laptops - screens equal to or greater than 992px wide) | |
| // sm (for tablets - screens equal to or greater than 768px wide) | |
| // xs (for phones - screens less than 768px wide) | |
| if (window.innerWidth >= 1200) { |
| export const isValidEmail = (email: string): boolean => { | |
| const match = String(email) | |
| .toLowerCase() | |
| .match( | |
| /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ | |
| ); |