@@ -5,7 +5,7 @@ var Mocha = require('../../lib/mocha');
5
5
var sinon = require ( 'sinon' ) ;
6
6
7
7
describe ( 'Mocha' , function ( ) {
8
- var opts = { reporter : function ( ) { } } ; // no output
8
+ var opts = { reporter : utils . noop } ; // no output
9
9
var sandbox ;
10
10
11
11
beforeEach ( function ( ) {
@@ -41,88 +41,59 @@ describe('Mocha', function() {
41
41
} ) ;
42
42
} ) ;
43
43
44
- describe ( '.run(fn)' , function ( ) {
45
- it ( 'should not raise errors if callback was not provided' , function ( ) {
46
- sandbox . stub ( Mocha . Runner . prototype , 'run' ) ;
44
+ describe ( '#allowUncaught()' , function ( ) {
45
+ it ( 'should set the allowUncaught option to true' , function ( ) {
47
46
var mocha = new Mocha ( opts ) ;
48
- expect ( function ( ) {
49
- mocha . run ( ) ;
50
- } , 'not to throw' ) ;
47
+ mocha . allowUncaught ( ) ;
48
+ expect ( mocha . options , 'to have property' , 'allowUncaught' , true ) ;
51
49
} ) ;
52
50
53
- it ( 'should execute the callback when complete ' , function ( done ) {
51
+ it ( 'should be chainable ' , function ( ) {
54
52
var mocha = new Mocha ( opts ) ;
55
- sandbox . stub ( Mocha . Runner . prototype , 'run' ) . callsArg ( 0 ) ;
56
- mocha . run ( done ) ;
57
- } ) ;
58
- } ) ;
59
-
60
- describe ( '.reporter("xunit").run(fn)' , function ( ) {
61
- it ( 'should not raise errors if callback was not provided' , function ( ) {
62
- var mocha = new Mocha ( ) ;
63
- expect ( function ( ) {
64
- try {
65
- mocha . reporter ( 'xunit' ) . run ( ) ;
66
- } catch ( e ) {
67
- console . log ( e ) ;
68
- expect . fail ( e . message ) ;
69
- }
70
- } , 'not to throw' ) ;
53
+ expect ( mocha . allowUncaught ( ) , 'to be' , mocha ) ;
71
54
} ) ;
72
55
} ) ;
73
56
74
- describe ( '.invert ()' , function ( ) {
75
- it ( 'should set the invert option to true' , function ( ) {
57
+ describe ( '#bail ()' , function ( ) {
58
+ it ( 'should set the suite._bail to true if there is no arguments ' , function ( ) {
76
59
var mocha = new Mocha ( opts ) ;
77
- mocha . invert ( ) ;
78
- expect ( mocha . options , 'to have property' , 'invert ', true ) ;
60
+ mocha . bail ( ) ;
61
+ expect ( mocha . suite . _bail , 'to be ' , true ) ;
79
62
} ) ;
80
63
81
64
it ( 'should be chainable' , function ( ) {
82
65
var mocha = new Mocha ( opts ) ;
83
- expect ( mocha . invert ( ) , 'to be' , mocha ) ;
66
+ expect ( mocha . bail ( ) , 'to be' , mocha ) ;
84
67
} ) ;
85
68
} ) ;
86
69
87
- describe ( '.ignoreLeaks()' , function ( ) {
88
- it ( 'should set the ignoreLeaks option to true when param equals true' , function ( ) {
89
- var mocha = new Mocha ( opts ) ;
90
- mocha . ignoreLeaks ( true ) ;
91
- expect ( mocha . options , 'to have property' , 'ignoreLeaks' , true ) ;
92
- } ) ;
93
-
94
- it ( 'should set the ignoreLeaks option to false when param equals false' , function ( ) {
95
- var mocha = new Mocha ( opts ) ;
96
- mocha . ignoreLeaks ( false ) ;
97
- expect ( mocha . options , 'to have property' , 'ignoreLeaks' , false ) ;
98
- } ) ;
99
-
100
- it ( 'should set the ignoreLeaks option to false when the param is undefined' , function ( ) {
70
+ describe ( '#checkLeaks()' , function ( ) {
71
+ it ( 'should set the ignoreLeaks option to false' , function ( ) {
101
72
var mocha = new Mocha ( opts ) ;
102
- mocha . ignoreLeaks ( ) ;
73
+ mocha . checkLeaks ( ) ;
103
74
expect ( mocha . options , 'to have property' , 'ignoreLeaks' , false ) ;
104
75
} ) ;
105
76
106
77
it ( 'should be chainable' , function ( ) {
107
78
var mocha = new Mocha ( opts ) ;
108
- expect ( mocha . ignoreLeaks ( ) , 'to be' , mocha ) ;
79
+ expect ( mocha . checkLeaks ( ) , 'to be' , mocha ) ;
109
80
} ) ;
110
81
} ) ;
111
82
112
- describe ( '.checkLeaks ()' , function ( ) {
113
- it ( 'should set the ignoreLeaks option to false ' , function ( ) {
83
+ describe ( '#delay ()' , function ( ) {
84
+ it ( 'should set the delay option to true ' , function ( ) {
114
85
var mocha = new Mocha ( opts ) ;
115
- mocha . checkLeaks ( ) ;
116
- expect ( mocha . options , 'to have property' , 'ignoreLeaks ' , false ) ;
86
+ mocha . delay ( ) ;
87
+ expect ( mocha . options , 'to have property' , 'delay ' , true ) ;
117
88
} ) ;
118
89
119
90
it ( 'should be chainable' , function ( ) {
120
91
var mocha = new Mocha ( opts ) ;
121
- expect ( mocha . checkLeaks ( ) , 'to be' , mocha ) ;
92
+ expect ( mocha . delay ( ) , 'to be' , mocha ) ;
122
93
} ) ;
123
94
} ) ;
124
95
125
- describe ( '. fullTrace()' , function ( ) {
96
+ describe ( '# fullTrace()' , function ( ) {
126
97
it ( 'should set the fullStackTrace option to true' , function ( ) {
127
98
var mocha = new Mocha ( opts ) ;
128
99
mocha . fullTrace ( ) ;
@@ -135,7 +106,53 @@ describe('Mocha', function() {
135
106
} ) ;
136
107
} ) ;
137
108
138
- describe ( '.growl()' , function ( ) {
109
+ describe ( '#globals()' , function ( ) {
110
+ it ( 'should be an empty array initially' , function ( ) {
111
+ var mocha = new Mocha ( ) ;
112
+ expect ( mocha . options . globals , 'to be empty' ) ;
113
+ } ) ;
114
+
115
+ it ( 'should be chainable' , function ( ) {
116
+ var mocha = new Mocha ( opts ) ;
117
+ expect ( mocha . globals ( ) , 'to be' , mocha ) ;
118
+ } ) ;
119
+
120
+ describe ( 'when argument is invalid' , function ( ) {
121
+ it ( 'should not modify the whitelist when given empty string' , function ( ) {
122
+ var mocha = new Mocha ( opts ) ;
123
+ mocha . globals ( '' ) ;
124
+ expect ( mocha . options . globals , 'to be empty' ) ;
125
+ } ) ;
126
+
127
+ it ( 'should not modify the whitelist when given empty array' , function ( ) {
128
+ var mocha = new Mocha ( opts ) ;
129
+ mocha . globals ( [ ] ) ;
130
+ expect ( mocha . options . globals , 'to be empty' ) ;
131
+ } ) ;
132
+ } ) ;
133
+
134
+ describe ( 'when argument is valid' , function ( ) {
135
+ var elem = 'foo' ;
136
+ var elem2 = 'bar' ;
137
+
138
+ it ( 'should add string to the whitelist' , function ( ) {
139
+ var mocha = new Mocha ( opts ) ;
140
+ mocha . globals ( elem ) ;
141
+ expect ( mocha . options . globals , 'to contain' , elem ) ;
142
+ expect ( mocha . options . globals , 'to have length' , 1 ) ;
143
+ } ) ;
144
+
145
+ it ( 'should add contents of string array to the whitelist' , function ( ) {
146
+ var mocha = new Mocha ( opts ) ;
147
+ var elems = [ elem , elem2 ] ;
148
+ mocha . globals ( elems ) ;
149
+ expect ( mocha . options . globals , 'to contain' , elem , elem2 ) ;
150
+ expect ( mocha . options . globals , 'to have length' , elems . length ) ;
151
+ } ) ;
152
+ } ) ;
153
+ } ) ;
154
+
155
+ describe ( '#growl()' , function ( ) {
139
156
describe ( 'if capable of notifications' , function ( ) {
140
157
it ( 'should set the growl option to true' , function ( ) {
141
158
var mocha = new Mocha ( opts ) ;
@@ -164,32 +181,45 @@ describe('Mocha', function() {
164
181
} ) ;
165
182
} ) ;
166
183
167
- describe ( '.useInlineDiffs ()' , function ( ) {
168
- it ( 'should set the useInlineDiffs option to true when param equals true' , function ( ) {
184
+ describe ( '#ignoreLeaks ()' , function ( ) {
185
+ it ( 'should set the ignoreLeaks option to true when param equals true' , function ( ) {
169
186
var mocha = new Mocha ( opts ) ;
170
- mocha . useInlineDiffs ( true ) ;
171
- expect ( mocha . options , 'to have property' , 'useInlineDiffs ' , true ) ;
187
+ mocha . ignoreLeaks ( true ) ;
188
+ expect ( mocha . options , 'to have property' , 'ignoreLeaks ' , true ) ;
172
189
} ) ;
173
190
174
- it ( 'should set the useInlineDiffs option to false when param equals false' , function ( ) {
191
+ it ( 'should set the ignoreLeaks option to false when param equals false' , function ( ) {
175
192
var mocha = new Mocha ( opts ) ;
176
- mocha . useInlineDiffs ( false ) ;
177
- expect ( mocha . options , 'to have property' , 'useInlineDiffs ' , false ) ;
193
+ mocha . ignoreLeaks ( false ) ;
194
+ expect ( mocha . options , 'to have property' , 'ignoreLeaks ' , false ) ;
178
195
} ) ;
179
196
180
- it ( 'should set the useInlineDiffs option to false when the param is undefined' , function ( ) {
197
+ it ( 'should set the ignoreLeaks option to false when the param is undefined' , function ( ) {
181
198
var mocha = new Mocha ( opts ) ;
182
- mocha . useInlineDiffs ( ) ;
183
- expect ( mocha . options , 'to have property' , 'useInlineDiffs ' , false ) ;
199
+ mocha . ignoreLeaks ( ) ;
200
+ expect ( mocha . options , 'to have property' , 'ignoreLeaks ' , false ) ;
184
201
} ) ;
185
202
186
203
it ( 'should be chainable' , function ( ) {
187
204
var mocha = new Mocha ( opts ) ;
188
- expect ( mocha . useInlineDiffs ( ) , 'to be' , mocha ) ;
205
+ expect ( mocha . ignoreLeaks ( ) , 'to be' , mocha ) ;
206
+ } ) ;
207
+ } ) ;
208
+
209
+ describe ( '#invert()' , function ( ) {
210
+ it ( 'should set the invert option to true' , function ( ) {
211
+ var mocha = new Mocha ( opts ) ;
212
+ mocha . invert ( ) ;
213
+ expect ( mocha . options , 'to have property' , 'invert' , true ) ;
214
+ } ) ;
215
+
216
+ it ( 'should be chainable' , function ( ) {
217
+ var mocha = new Mocha ( opts ) ;
218
+ expect ( mocha . invert ( ) , 'to be' , mocha ) ;
189
219
} ) ;
190
220
} ) ;
191
221
192
- describe ( '. noHighlighting()' , function ( ) {
222
+ describe ( '# noHighlighting()' , function ( ) {
193
223
// :NOTE: Browser-only option...
194
224
it ( 'should set the noHighlighting option to true' , function ( ) {
195
225
var mocha = new Mocha ( opts ) ;
@@ -203,57 +233,79 @@ describe('Mocha', function() {
203
233
} ) ;
204
234
} ) ;
205
235
206
- describe ( '.allowUncaught()' , function ( ) {
207
- it ( 'should set the allowUncaught option to true' , function ( ) {
208
- var mocha = new Mocha ( opts ) ;
209
- mocha . allowUncaught ( ) ;
210
- expect ( mocha . options , 'to have property' , 'allowUncaught' , true ) ;
236
+ describe ( '#reporter()' , function ( ) {
237
+ it ( 'should throw reporter error if an invalid reporter is given' , function ( ) {
238
+ var updatedOpts = { reporter : 'invalidReporter' , reporterOptions : { } } ;
239
+ var throwError = function ( ) {
240
+ // eslint-disable-next-line no-new
241
+ new Mocha ( updatedOpts ) ;
242
+ } ;
243
+ expect ( throwError , 'to throw' , {
244
+ message : "invalid reporter 'invalidReporter'" ,
245
+ code : 'ERR_MOCHA_INVALID_REPORTER' ,
246
+ reporter : 'invalidReporter'
247
+ } ) ;
211
248
} ) ;
212
249
213
250
it ( 'should be chainable' , function ( ) {
214
251
var mocha = new Mocha ( opts ) ;
215
- expect ( mocha . allowUncaught ( ) , 'to be' , mocha ) ;
252
+ expect ( mocha . reporter ( ) , 'to be' , mocha ) ;
216
253
} ) ;
217
254
} ) ;
218
255
219
- describe ( '.delay( )' , function ( ) {
220
- it ( 'should set the delay option to true ' , function ( ) {
256
+ describe ( '#run(fn )' , function ( ) {
257
+ it ( 'should execute the callback when complete ' , function ( done ) {
221
258
var mocha = new Mocha ( opts ) ;
222
- mocha . delay ( ) ;
223
- expect ( mocha . options , 'to have property' , 'delay' , true ) ;
259
+ sandbox . stub ( Mocha . Runner . prototype , 'run' ) . callsArg ( 0 ) ;
260
+ mocha . run ( done ) ;
224
261
} ) ;
225
262
226
- it ( 'should be chainable' , function ( ) {
263
+ it ( 'should not raise errors if callback was not provided' , function ( ) {
264
+ sandbox . stub ( Mocha . Runner . prototype , 'run' ) ;
227
265
var mocha = new Mocha ( opts ) ;
228
- expect ( mocha . delay ( ) , 'to be' , mocha ) ;
266
+ expect ( function ( ) {
267
+ mocha . run ( ) ;
268
+ } , 'not to throw' ) ;
269
+ } ) ;
270
+
271
+ describe ( '#reporter("xunit")#run(fn)' , function ( ) {
272
+ // :TBD: Why does specifying reporter differentiate this test from preceding one
273
+ it ( 'should not raise errors if callback was not provided' , function ( ) {
274
+ var mocha = new Mocha ( ) ;
275
+ expect ( function ( ) {
276
+ try {
277
+ mocha . reporter ( 'xunit' ) . run ( ) ;
278
+ } catch ( e ) {
279
+ console . log ( e ) ;
280
+ expect . fail ( e . message ) ;
281
+ }
282
+ } , 'not to throw' ) ;
283
+ } ) ;
229
284
} ) ;
230
285
} ) ;
231
286
232
- describe ( '.bail ()' , function ( ) {
233
- it ( 'should set the suite._bail to true if there is no arguments ' , function ( ) {
287
+ describe ( '#useInlineDiffs ()' , function ( ) {
288
+ it ( 'should set the useInlineDiffs option to true when param equals true ' , function ( ) {
234
289
var mocha = new Mocha ( opts ) ;
235
- mocha . bail ( ) ;
236
- expect ( mocha . suite . _bail , 'to be ' , true ) ;
290
+ mocha . useInlineDiffs ( true ) ;
291
+ expect ( mocha . options , 'to have property' , 'useInlineDiffs ', true ) ;
237
292
} ) ;
238
293
239
- it ( 'should be chainable ' , function ( ) {
294
+ it ( 'should set the useInlineDiffs option to false when param equals false ' , function ( ) {
240
295
var mocha = new Mocha ( opts ) ;
241
- expect ( mocha . bail ( ) , 'to be' , mocha ) ;
296
+ mocha . useInlineDiffs ( false ) ;
297
+ expect ( mocha . options , 'to have property' , 'useInlineDiffs' , false ) ;
242
298
} ) ;
243
- } ) ;
244
299
245
- describe ( 'error handling' , function ( ) {
246
- it ( 'should throw reporter error if an invalid reporter is given' , function ( ) {
247
- var updatedOpts = { reporter : 'invalidReporter' , reporterOptions : { } } ;
248
- var throwError = function ( ) {
249
- // eslint-disable-next-line no-new
250
- new Mocha ( updatedOpts ) ;
251
- } ;
252
- expect ( throwError , 'to throw' , {
253
- message : "invalid reporter 'invalidReporter'" ,
254
- code : 'ERR_MOCHA_INVALID_REPORTER' ,
255
- reporter : 'invalidReporter'
256
- } ) ;
300
+ it ( 'should set the useInlineDiffs option to false when the param is undefined' , function ( ) {
301
+ var mocha = new Mocha ( opts ) ;
302
+ mocha . useInlineDiffs ( ) ;
303
+ expect ( mocha . options , 'to have property' , 'useInlineDiffs' , false ) ;
304
+ } ) ;
305
+
306
+ it ( 'should be chainable' , function ( ) {
307
+ var mocha = new Mocha ( opts ) ;
308
+ expect ( mocha . useInlineDiffs ( ) , 'to be' , mocha ) ;
257
309
} ) ;
258
310
} ) ;
259
311
} ) ;
0 commit comments