當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript minimumAgeValidator.MinimumAgeValidatorConstraint類代碼示例

本文整理匯總了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)
    })
  })
})
開發者ID:hmcts,項目名稱:cmc-citizen-frontend,代碼行數:44,代碼來源:isInThePast.ts

示例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)
 })
開發者ID:hmcts,項目名稱:cmc-citizen-frontend,代碼行數:3,代碼來源:isInThePast.ts

示例3: expect

 expect(() => constraint.validate(null, yearsLimit(undefined))).to.throw(Error, minMessage)
開發者ID:hmcts,項目名稱:cmc-citizen-frontend,代碼行數:1,代碼來源:isInThePast.ts


注:本文中的forms/validation/validators/minimumAgeValidator.MinimumAgeValidatorConstraint類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。