本文整理匯總了TypeScript中forms/validation/validators/minimumAgeValidator.MinimumAgeValidatorConstraint類的典型用法代碼示例。如果您正苦於以下問題:TypeScript MinimumAgeValidatorConstraint類的具體用法?TypeScript MinimumAgeValidatorConstraint怎麽用?TypeScript MinimumAgeValidatorConstraint使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了MinimumAgeValidatorConstraint類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: describe
describe('MinimumAgeValidatorConstraint', () => {
const constraint: MinimumAgeValidatorConstraint = new MinimumAgeValidatorConstraint()
const minMessage: string = 'Min Years in the past has to be specified and positive value'
describe('validate', () => {
const today = moment()
it('should throw an error if minYears constraint is not set', () => {
expect(() => constraint.validate(null, yearsLimit(undefined))).to.throw(Error, minMessage)
})
it('should accept past date grater than minimum age', () => {
expect(constraint.validate(new LocalDate(today.year() - 19, today.month() + 1, today.date()), yearsLimit(18))).to.be.equal(true)
})
it('should accept undefined value', () => {
expect(constraint.validate(undefined, yearsLimit(1))).to.be.equal(true)
})
it('should accept undefined value', () => {
expect(constraint.validate(undefined, yearsLimit(1))).to.be.equal(true)
})
it('should reject values other then LocalDate', () => {
expect(constraint.validate({}, yearsLimit(1))).to.be.equal(false)
})
it('should reject future date', () => {
expect(constraint.validate(new LocalDate(today.year(), today.month() + 1, today.date() + 1), yearsLimit(1))).to.be.equal(false)
})
it('should reject current date', () => {
expect(constraint.validate(new LocalDate(today.year(), today.month() + 1, today.date()), yearsLimit(1))).to.be.equal(false)
})
it('should reject past date out of the range', () => {
expect(constraint.validate(new LocalDate(today.year() - 17, today.month() + 1, today.date()), yearsLimit(18))).to.be.equal(false)
})
it('should accept past date within range', () => {
expect(constraint.validate(new LocalDate(today.year() - 1, today.month() + 1, today.date()), yearsLimit(1))).to.be.equal(true)
})
})
})
示例2: it
it('should accept past date within range', () => {
expect(constraint.validate(new LocalDate(today.year() - 1, today.month() + 1, today.date()), yearsLimit(1))).to.be.equal(true)
})
示例3: expect
expect(() => constraint.validate(null, yearsLimit(undefined))).to.throw(Error, minMessage)