-
Notifications
You must be signed in to change notification settings - Fork 60
/
validators.test.js
39 lines (31 loc) · 1.24 KB
/
validators.test.js
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
import { required } from './validators'
import { regexp } from './validators'
describe('require validator', function() {
it('should throw message when argument is not supplied', () => {
(() => {required('title')({})})
.should.throw('Argument \'title\' is required but not supplied.')
})
it('should not throw when argument is supplied', () => {
(() => {required('title')({'title': 'asdf'})}).should.not.throw()
})
it('should throw message when argument is not supplied', () => {
(() => {required('foo')({'title': ''})})
.should.throw('Argument \'foo\' is required but not supplied.')
})
})
describe('regexp validator', function() {
it('should throw error when argument doesn\'t match regexp', () => {
(() => {regexp('title', /bar/)({'title': 'foo'})})
.should.throw('Argument \'title\' is invalid')
})
it('doesn\'t throw when format is valid', () => {
(() => {regexp('title', /bar/)({'title': 'bar'})}).should.not.throw()
})
it('correct error message is shown', () => {
(() => {regexp('class', /bar/)({'class': 'foo'})})
.should.throw('Argument \'class\' is invalid')
})
it('correct regexp is used', () => {
(() => {regexp('title', /[0-9]+/)({'title': '145'})}).should.not.throw()
})
})