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


TypeScript maximumAgeValidator.MaximumAgeValidatorConstraint類代碼示例

本文整理匯總了TypeScript中forms/validation/validators/maximumAgeValidator.MaximumAgeValidatorConstraint的典型用法代碼示例。如果您正苦於以下問題:TypeScript MaximumAgeValidatorConstraint類的具體用法?TypeScript MaximumAgeValidatorConstraint怎麽用?TypeScript MaximumAgeValidatorConstraint使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了MaximumAgeValidatorConstraint類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: describe

describe('MaximumAgeValidatorConstraint', () => {
  const constraint: MaximumAgeValidatorConstraint = new MaximumAgeValidatorConstraint()
  const maxMessage: string = 'Max Years in the past has to be specified and positive value'

  describe('validate', () => {
    const today = moment()

    it('should throw an error if maxYears constraint is not set', () => {
      expect(() => constraint.validate(null, yearsLimit(undefined))).to.throw(Error, maxMessage)
    })

    it('should accept past date lesser than maximum age', () => {
      expect(constraint.validate(new LocalDate(today.year() - 149, today.month() + 1, today.date()), yearsLimit(150))).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 past date out of the range', () => {
      expect(constraint.validate(new LocalDate(today.year() - 151, today.month() + 1, today.date()), yearsLimit(150))).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,代碼行數:36,代碼來源: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, maxMessage)
開發者ID:hmcts,項目名稱:cmc-citizen-frontend,代碼行數:1,代碼來源:isInThePast.ts


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