本文整理汇总了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
})