test(forms): add test on applying unicode flag (#20819)

PR Close #20819
This commit is contained in:
Huáng Jùnliàng 2017-12-06 22:30:00 +08:00 committed by Igor Minar
parent dde1d67232
commit 619b8ab822
1 changed files with 8 additions and 0 deletions

View File

@ -11,6 +11,7 @@ import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
import {AbstractControl, AsyncValidatorFn, FormArray, FormControl, Validators} from '@angular/forms'; import {AbstractControl, AsyncValidatorFn, FormArray, FormControl, Validators} from '@angular/forms';
import {normalizeAsyncValidator} from '@angular/forms/src/directives/normalize_validator'; import {normalizeAsyncValidator} from '@angular/forms/src/directives/normalize_validator';
import {AsyncValidator, ValidationErrors, ValidatorFn} from '@angular/forms/src/directives/validators'; import {AsyncValidator, ValidationErrors, ValidatorFn} from '@angular/forms/src/directives/validators';
import {browserDetection} from '@angular/platform-browser/testing/src/browser_util';
import {Observable, of , timer} from 'rxjs'; import {Observable, of , timer} from 'rxjs';
import {first, map} from 'rxjs/operators'; import {first, map} from 'rxjs/operators';
@ -274,6 +275,13 @@ import {first, map} from 'rxjs/operators';
it('should not error on "undefined" pattern', it('should not error on "undefined" pattern',
() => expect(Validators.pattern(undefined !)(new FormControl('aaAA'))).toBeNull()); () => expect(Validators.pattern(undefined !)(new FormControl('aaAA'))).toBeNull());
if (browserDetection.supportsRegExUnicodeFlag) {
it('should apply unicode flag to pattern when supported', () => {
expect(Validators.pattern('[\u{10000}-\u{10001}]')(new FormControl('\u{10000}')))
.toBeNull();
});
}
it('should work with pattern string containing both boundary symbols', it('should work with pattern string containing both boundary symbols',
() => expect(Validators.pattern('^[aA]*$')(new FormControl('aaAA'))).toBeNull()); () => expect(Validators.pattern('^[aA]*$')(new FormControl('aaAA'))).toBeNull());