-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.spec.js
88 lines (68 loc) · 1.85 KB
/
index.spec.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
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
85
86
87
88
/*
* mandatory
*
* Copyright(c) 2014 André König <[email protected]>
* MIT Licensed
*
*/
/**
* @author André König <[email protected]>
*
*/
/* global: ,describe,it,expect */
'use strict';
var mandatory = require('./');
describe('The "mandatory" module', function () {
it('should be able to detect a wrong "number"', function () {
var error = false;
try {
mandatory('0').is('number');
} catch (e) {
error = true;
expect(e).toBeDefined();
}
expect(error).toBe(true);
});
it('should be able to detect a wrong "string"', function () {
var error = false;
try {
mandatory(0).is('string');
} catch (e) {
error = true;
expect(e).toBeDefined();
}
expect(error).toBe(true);
});
it('should be able to detect a wrong "object"', function () {
var error = false;
try {
mandatory([]).is('object');
} catch (e) {
error = true;
expect(e).toBeDefined();
}
expect(error).toBe(true);
});
it('should be able to detect a wrong "array"', function () {
var error = false;
try {
mandatory({}).is('array');
} catch (e) {
error = true;
expect(e).toBeDefined();
}
expect(error).toBe(true);
});
it('should provide the functionality to change the error message', function () {
var error = false;
var message = 'Wrong type';
try {
mandatory({}).is('array', message);
} catch (e) {
error = true;
expect(e).toBeDefined();
expect(e.message).toBe(message);
}
expect(error).toBe(true);
});
});