|
|
|
@ -5,6 +5,7 @@ import { validateCreditCard } from '../validators/credit-card.validator'; |
|
|
|
import { validateRequired } from '../validators/required.validator'; |
|
|
|
import { validateStringLength } from '../validators/string-length.validator'; |
|
|
|
import { validateUrl } from '../validators/url.validator'; |
|
|
|
import { validateUniqueCharacter } from '../validators'; |
|
|
|
|
|
|
|
const emailAddress = () => Validators.email; |
|
|
|
|
|
|
|
@ -181,4 +182,25 @@ describe('Validators', () => { |
|
|
|
expect(control.errors).toEqual(expected); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
describe('Unique Character Validator', () => { |
|
|
|
const error = { uniqueCharacter: true }; |
|
|
|
|
|
|
|
test.each` |
|
|
|
input | expected |
|
|
|
${undefined} | ${null} |
|
|
|
${null} | ${null} |
|
|
|
${''} | ${null} |
|
|
|
${'password'} | ${error} |
|
|
|
${'123456789'} | ${null} |
|
|
|
${'1q2w3E*'} | ${null} |
|
|
|
${'password123'} | ${error} |
|
|
|
`('should return $expected when input is $input', ({ input, expected }) => {
|
|
|
|
const control = new FormControl(input, [validateUniqueCharacter()]); |
|
|
|
control.markAsDirty({ onlySelf: true }); |
|
|
|
control.updateValueAndValidity({ onlySelf: true, emitEvent: false }); |
|
|
|
|
|
|
|
expect(control.errors).toEqual(expected); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|