@@ -21,6 +21,7 @@ describe('Mocha', function() {
21
21
sandbox . stub ( Mocha . prototype , 'useColors' ) . returnsThis ( ) ;
22
22
sandbox . stub ( utils , 'deprecate' ) ;
23
23
sandbox . stub ( Mocha . prototype , 'timeout' ) . returnsThis ( ) ;
24
+ sandbox . stub ( Mocha . prototype , 'globals' ) . returnsThis ( ) ;
24
25
} ) ;
25
26
26
27
describe ( 'when "useColors" option is defined' , function ( ) {
@@ -64,6 +65,44 @@ describe('Mocha', function() {
64
65
) ;
65
66
} ) ;
66
67
} ) ;
68
+
69
+ describe ( 'when "options.global" is provided' , function ( ) {
70
+ it ( 'should pass "options.global" to #globals()' , function ( ) {
71
+ // eslint-disable-next-line no-new
72
+ new Mocha ( { global : [ 'singular' ] } ) ;
73
+ expect ( Mocha . prototype . globals , 'to have a call satisfying' , [
74
+ [ 'singular' ]
75
+ ] ) . and ( 'was called once' ) ;
76
+ } ) ;
77
+ it ( 'should delete mocha.options.global' , function ( ) {
78
+ var mocha = new Mocha ( { global : [ 'singular' ] } ) ;
79
+ expect ( mocha . options . global , 'to be' , undefined ) ;
80
+ } ) ;
81
+ } ) ;
82
+
83
+ describe ( 'when "options.globals" is provided' , function ( ) {
84
+ it ( 'should pass "options.globals" to #globals()' , function ( ) {
85
+ // eslint-disable-next-line no-new
86
+ new Mocha ( { globals : [ 'plural' ] } ) ;
87
+ expect ( Mocha . prototype . globals , 'to have a call satisfying' , [
88
+ [ 'plural' ]
89
+ ] ) . and ( 'was called once' ) ;
90
+ } ) ;
91
+ } ) ;
92
+
93
+ describe ( 'when "options.global" AND "options.globals" are provided' , function ( ) {
94
+ it ( 'should pass "options.global" to #globals(), ignoring "options.globals"' , function ( ) {
95
+ // eslint-disable-next-line no-new
96
+ new Mocha ( { global : [ 'singular' ] , globals : [ 'plural' ] } ) ;
97
+ expect ( Mocha . prototype . globals , 'to have a call satisfying' , [
98
+ [ 'singular' ]
99
+ ] ) . and ( 'was called once' ) ;
100
+ } ) ;
101
+ it ( 'should delete mocha.options.global' , function ( ) {
102
+ var mocha = new Mocha ( { global : [ 'singular' ] , globals : [ 'plural' ] } ) ;
103
+ expect ( mocha . options . global , 'to be' , undefined ) ;
104
+ } ) ;
105
+ } ) ;
67
106
} ) ;
68
107
69
108
describe ( '#allowUncaught()' , function ( ) {
@@ -159,6 +198,7 @@ describe('Mocha', function() {
159
198
describe ( 'when argument is valid' , function ( ) {
160
199
var elem = 'foo' ;
161
200
var elem2 = 'bar' ;
201
+ var elem3 = 'baz' ;
162
202
163
203
it ( 'should add string to the whitelist' , function ( ) {
164
204
var mocha = new Mocha ( opts ) ;
@@ -174,6 +214,14 @@ describe('Mocha', function() {
174
214
expect ( mocha . options . globals , 'to contain' , elem , elem2 ) ;
175
215
expect ( mocha . options . globals , 'to have length' , elems . length ) ;
176
216
} ) ;
217
+
218
+ it ( 'should not have duplicates' , function ( ) {
219
+ var mocha = new Mocha ( { globals : [ elem , elem2 ] } ) ;
220
+ var elems = [ elem , elem2 , elem3 ] ;
221
+ mocha . globals ( elems ) ;
222
+ expect ( mocha . options . globals , 'to contain' , elem , elem2 , elem3 ) ;
223
+ expect ( mocha . options . globals , 'to have length' , elems . length ) ;
224
+ } ) ;
177
225
} ) ;
178
226
} ) ;
179
227
0 commit comments