1
1
/* eslint-disable
2
2
strict,
3
- no-shadow
3
+ no-shadow,
4
+ arrow-body-style
4
5
*/
5
6
6
7
'use strict' ;
@@ -21,10 +22,11 @@ test('Valid', () => {
21
22
boolean : true ,
22
23
instance : new RegExp ( '' ) ,
23
24
} ;
25
+ const validate = ( ) => {
26
+ return validateOptions ( 'test/fixtures/schema.json' , options , '{Name}' ) ;
27
+ } ;
24
28
25
- expect ( validateOptions ( 'test/fixtures/schema.json' , options , 'Loader' ) ) . toBe (
26
- true
27
- ) ;
29
+ expect ( validate ( ) ) . toBe ( true ) ;
28
30
} ) ;
29
31
30
32
describe ( 'Error' , ( ) => {
@@ -42,15 +44,16 @@ describe('Error', () => {
42
44
instance ( ) { } ,
43
45
} ;
44
46
45
- const validate = ( ) =>
46
- validateOptions ( 'test/fixtures/schema.json' , options , '{Name}' ) ;
47
+ const validate = ( ) => {
48
+ return validateOptions ( 'test/fixtures/schema.json' , options , '{Name}' ) ;
49
+ } ;
47
50
48
- test ( 'should throw error ' , ( ) => {
51
+ test ( 'Throws ' , ( ) => {
49
52
expect ( validate ) . toThrowError ( ) ;
50
53
expect ( validate ) . toThrowErrorMatchingSnapshot ( ) ;
51
54
} ) ;
52
55
53
- test ( 'should have errors for every option key ' , ( ) => {
56
+ test ( 'Errors ' , ( ) => {
54
57
try {
55
58
validate ( ) ;
56
59
} catch ( err ) {
@@ -70,4 +73,66 @@ describe('Error', () => {
70
73
expect ( err . errors ) . toMatchSnapshot ( ) ;
71
74
}
72
75
} ) ;
76
+
77
+ describe ( 'Messages' , ( ) => {
78
+ test ( 'Default' , ( ) => {
79
+ const options = {
80
+ type ( ) { } ,
81
+ array : [ '' ] ,
82
+ string : 1 ,
83
+ object : {
84
+ prop : false ,
85
+ object : {
86
+ prop : false ,
87
+ } ,
88
+ } ,
89
+ boolean : true ,
90
+ instance : new RegExp ( '' ) ,
91
+ } ;
92
+
93
+ const validate = ( ) => {
94
+ return validateOptions ( 'test/fixtures/schema.json' , options , '{Name}' ) ;
95
+ } ;
96
+
97
+ try {
98
+ validate ( ) ;
99
+ } catch ( err ) {
100
+ err . errors . forEach ( ( err ) => expect ( err ) . toMatchSnapshot ( ) ) ;
101
+
102
+ expect ( err . message ) . toMatchSnapshot ( ) ;
103
+ }
104
+ } ) ;
105
+
106
+ test ( 'Customized' , ( ) => {
107
+ const options = {
108
+ type ( ) { } ,
109
+ array : [ '' ] ,
110
+ string : 1 ,
111
+ object : {
112
+ prop : false ,
113
+ object : {
114
+ prop : false ,
115
+ } ,
116
+ } ,
117
+ boolean : true ,
118
+ instance : new RegExp ( '' ) ,
119
+ } ;
120
+
121
+ const validate = ( ) => {
122
+ return validateOptions (
123
+ 'test/fixtures/errors/schema.json' ,
124
+ options ,
125
+ '{Name}'
126
+ ) ;
127
+ } ;
128
+
129
+ try {
130
+ validate ( ) ;
131
+ } catch ( err ) {
132
+ err . errors . forEach ( ( err ) => expect ( err ) . toMatchSnapshot ( ) ) ;
133
+
134
+ expect ( err . message ) . toMatchSnapshot ( ) ;
135
+ }
136
+ } ) ;
137
+ } ) ;
73
138
} ) ;
0 commit comments