當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。