当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript isCountrySupported.CheckCountryConstraint类代码示例

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


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

示例1: describe

describe('IsCountrySupported', () => {
  const constraint: CheckCountryConstraint = new CheckCountryConstraint()

  describe('validate', () => {

    context('should return true when ', () => {
      it('given an undefined value', async () => {
        expect(await constraint.validate(undefined)).to.be.true
      })

      it('given a null value', async () => {
        expect(await constraint.validate(null)).to.be.true
      })

      it('given an empty string value', async () => {
        expect(await constraint.validate('')).to.be.true
      })

      it('given an invalid postcode', async () => {
        nock(mockPostcodeServer)
          .get(mockPostcodePath)
          .reply(404)

        expect(await constraint.validate('2SW1AN', validationArgs(Country.all()))).to.be.true
      })

      it('the postcode lookup client returns an error', async () => {
        nock(mockPostcodeServer)
          .get(mockPostcodePath)
          .reply(500)

        expect(await constraint.validate('SW2 1AN', validationArgs(Country.all()))).to.be.true
      })

      it('given a valid postcode', async () => {
        nock(mockPostcodeServer)
          .get(mockPostcodePath)
          .reply(200, mockPostcodeLookupResponse)
        nock(mockCountryServer)
          .get(mockCountryPath)
          .reply(200, mockCountryLookupResponse)

        expect(await constraint.validate('SW21AN', validationArgs(Country.all()))).to.be.true
      })
    })

    context('should return false when ', () => {
      it('given a postcode that is not in the accepted list', async () => {
        nock(mockPostcodeServer)
          .get(mockPostcodePath)
          .reply(200, mockScottishPostcodeLookupResponse)
        nock(mockCountryServer)
          .get(mockCountryPath)
          .reply(200, mockScottishCountryLookupResponse)

        expect(await constraint.validate('EH9 1SH', validationArgs(Country.defendantCountries()))).to.be.false
      })

      it('given an Isle of Man postcode', async () => {
        expect(await constraint.validate('IM99 1AD', validationArgs(Country.defendantCountries()))).to.be.false
      })
    })
  })
})
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:64,代码来源:isCountrySupported.ts

示例2: it

      it('the postcode lookup client returns an error', async () => {
        nock(mockPostcodeServer)
          .get(mockPostcodePath)
          .reply(500)

        expect(await constraint.validate('SW2 1AN', validationArgs(Country.all()))).to.be.true
      })
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:7,代码来源:isCountrySupported.ts


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