本文整理匯總了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
})
})
})
})
示例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
})