1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
'use strict'
/**
* Test dependencies
*/
const cwd = process.cwd()
const path = require('path')
const chai = require('chai')
/**
* Assertions
*/
chai.should()
let expect = chai.expect
/**
* Code under test
*/
const formats = require('../src/Formats')
const Formats = formats.constructor
/**
* Tests
*/
describe('Formats', () => {
describe('module', () => {
it('should be an instance of Formats', () => {
expect(formats).to.be.instanceof(Formats)
})
})
describe('initialize', () => {
it('should return an instance of Formats', () => {
Formats.initialize().should.be.instanceof(Formats)
})
})
describe('register', () => {
it('should require "name" argument to be a string', () => {
expect(() => {
formats.register(null)
}).to.throw('Format name must be a string')
})
it('should validate pattern is allowed by JSON Schema patterns')
it('should add the pattern to the map', () => {
formats.register('ends-with-foo', /foo$/)
formats['ends-with-foo'].should.be.instanceof(RegExp)
})
})
describe('resolve', () => {
it('should return a known pattern', () => {
formats.resolve('uri').should.be.instanceof(RegExp)
})
it('should throw an error with unknown pattern', () => {
expect(() => {
formats.resolve('unknown')
}).to.throw('Unknown JSON Schema format.')
})
})
describe('test', () => {
it('should validate a value with a known known pattern', () => {
formats.test('uri', '/').should.equal(true)
formats.test('uri', '&').should.equal(false)
})
it('should throw an error with unknown pattern', () => {
expect(() => {
formats.test('unknown', 'value')
}).to.throw('Unknown JSON Schema format.')
})
})
describe('date-time', () => {})
describe('uri', () => {})
describe('email', () => {})
describe('ipv4', () => {})
describe('ipv6', () => {})
describe('hostname', () => {})
})
|