• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript class-validator.Validator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中@hmcts/class-validator.Validator的典型用法代码示例。如果您正苦于以下问题:TypeScript Validator类的具体用法?TypeScript Validator怎么用?TypeScript Validator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Validator类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: describe

  describe('validation', () => {

    const validator: Validator = new Validator()

    context('should accept', () => {
      it('when both undefined', () => {
        const errors = validator.validateSync(new TimelineRow(undefined, undefined))

        expect(errors.length).to.equal(0)
      })

      it('when both are valid strings', () => {
        const errors = validator.validateSync(new TimelineRow('Date', 'description'))

        expect(errors.length).to.equal(0)
      })
    })

    context('should reject', () => {
      it('when date given, but no description', () => {
        const errors = validator.validateSync(new TimelineRow('May', ''))

        expect(errors.length).to.equal(1)
        expectValidationError(errors, ValidationErrors.DESCRIPTION_REQUIRED)
      })

      it('when description given, but no date', () => {
        const errors = validator.validateSync(new TimelineRow('', 'Let me tell you what happened'))

        expect(errors.length).to.equal(1)
        expectValidationError(errors, GlobalValidationErrors.DATE_REQUIRED)
      })

      it('when both args are empty strings', () => {
        const errors = validator.validateSync(new TimelineRow('', ''))

        expect(errors.length).to.equal(2)
        expectValidationError(errors, GlobalValidationErrors.DATE_REQUIRED)
        expectValidationError(errors, ValidationErrors.DESCRIPTION_REQUIRED)
      })

      it('when date is too long', () => {
        const errors = validator.validateSync(
          new TimelineRow(generateString(ValidationConstraints.DATE_MAX_LENGTH + 1), 'description')
        )

        expect(errors.length).to.equal(1)
        expectValidationError(
          errors, ValidationErrors.DATE_TOO_LONG.replace('$constraint1', ValidationConstraints.DATE_MAX_LENGTH.toString())
        )
      })

      it('when description is too long', () => {
        const errors = validator.validateSync(
          new TimelineRow('date', generateString(DefaultValidationConstraints.FREE_TEXT_MAX_LENGTH + 1))
        )

        expect(errors.length).to.equal(1)
        expectValidationError(errors, GlobalValidationErrors.TEXT_TOO_LONG)
      })
    })
  })
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:62,代码来源:timelineRow.ts


示例2: describe

describe('HowMuchHaveYouPaid', () => {
  const validator: Validator = new Validator()

  context('should not be valid when', () => {
    context('amount is', () => {
      it('eq 0', () => {
        const errors = validator.validateSync(new HowMuchHaveYouPaid(0, validLocalDate, validText))
        expect(errors.length).to.equal(1)
        expectValidationError(errors, ValidationErrors.AMOUNT_NOT_VALID)
      })

      it('less than 0', () => {
        const errors = validator.validateSync(new HowMuchHaveYouPaid(-10, validLocalDate, validText))
        expect(errors.length).to.equal(1)
        expectValidationError(errors, ValidationErrors.AMOUNT_NOT_VALID)
      })
    })

    context('date is', () => {
      it('in the future', () => {
        const dateInThePast = LocalDate.fromObject({ day: 10, month: 10, year: 2200 })
        const errors = validator.validateSync(new HowMuchHaveYouPaid(validAmount, dateInThePast, validText))
        expect(errors.length).to.equal(1)
        expectValidationError(errors, ValidationErrors.VALID_PAST_DATE)
      })

      it('invalid', () => {
        const dateInThePast = LocalDate.fromObject({ day: 33, month: 13, year: 1990 })
        const errors = validator.validateSync(new HowMuchHaveYouPaid(validAmount, dateInThePast, validText))
        expect(errors.length).to.equal(1)
        expectValidationError(errors, LocalDateValidationErrors.DAY_NOT_VALID)
      })

      it('undefined', () => {
        const errors = validator.validateSync(new HowMuchHaveYouPaid(validAmount, undefined, validText))
        expect(errors.length).to.equal(1)
        expectValidationError(errors, DefaultValidationErrors.DATE_REQUIRED)
      })
    })

    context('text is', () => {
      it('empty', () => {
        const errors = validator.validateSync(new HowMuchHaveYouPaid(validAmount, validLocalDate, ''))
        expect(errors.length).to.equal(1)
        expectValidationError(errors, ValidationErrors.EXPLANATION_REQUIRED)
      })

      it('undefined', () => {
        const errors = validator.validateSync(new HowMuchHaveYouPaid(validAmount, validLocalDate, undefined))
        expect(errors.length).to.equal(1)
        expectValidationError(errors, ValidationErrors.EXPLANATION_REQUIRED)
      })

      it('too long', () => {
        const errors = validator.validateSync(new HowMuchHaveYouPaid(
          validAmount, validLocalDate, generateString(ValidationConstraints.FREE_TEXT_MAX_LENGTH + 1)
        ))
        expect(errors.length).to.equal(1)
        expectValidationError(errors, DefaultValidationErrors.TEXT_TOO_LONG)
      })
    })
  })
})
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:63,代码来源:howMuchHaveYouPaid.ts


示例3: it

      it('should return an error when `schedule` is invalid', () => {
        const errors = validator.validateSync(new ExpenseSource('Source name', 100, new IncomeExpenseSchedule('UNKNOWN', 'Unknown')))

        expect(errors.length).to.equal(1)
        expectValidationError(errors, ValidationErrors.SCHEDULE_SELECT_AN_OPTION('Source name'))
      })
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:6,代码来源:expenseSource.ts


示例4: it

      it('when both are valid strings', () => {
        const errors = validator.validateSync(new TimelineRow('Date', 'description'))

        expect(errors.length).to.equal(0)
      })
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:5,代码来源:timelineRow.ts


示例5: it

 it('in the future', () => {
   const dateInThePast = LocalDate.fromObject({ day: 10, month: 10, year: 2200 })
   const errors = validator.validateSync(new HowMuchHaveYouPaid(validAmount, dateInThePast, validText))
   expect(errors.length).to.equal(1)
   expectValidationError(errors, ValidationErrors.VALID_PAST_DATE)
 })
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:6,代码来源:howMuchHaveYouPaid.ts


示例6: it

 it('should return no error', () => {
   const errors = validator.validateSync(new IncomeExpenseSource(100, IncomeExpenseSchedule.MONTH))
   expect(errors.length).to.equal(0)
 })
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:4,代码来源:incomeExpenseSource.ts


示例7: it

      it('when declared = true and one valid row and many many empty ones given', () => {
        const o: DebtRow = DebtRow.empty()
        const errors = validator.validateSync(new Debts(true, [o, o, o, o, new DebtRow('card', 1, 1), o, o, o, o]))

        expect(errors.length).to.equal(0)
      })
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:6,代码来源:debts.ts



注:本文中的@hmcts/class-validator.Validator类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap