@@ -177,23 +177,47 @@ describe('random', () => {
177
177
expect ( actual ) . toHaveLength ( 5 ) ;
178
178
} ) ;
179
179
180
- it ( 'should be able to ban some characters' , ( ) => {
180
+ it ( 'should be able to ban all alphabetic characters' , ( ) => {
181
+ const bannedChars = 'abcdefghijklmnopqrstuvwxyz' . split ( '' ) ;
181
182
const alphaText = faker . random . alphaNumeric ( 5 , {
182
- bannedChars : [ 'a' , 'p' ] ,
183
+ bannedChars,
183
184
} ) ;
184
185
185
186
expect ( alphaText ) . toHaveLength ( 5 ) ;
186
- expect ( alphaText ) . match ( / [ b - o q - z ] / ) ;
187
+ for ( const bannedChar of bannedChars ) {
188
+ expect ( alphaText ) . not . includes ( bannedChar ) ;
189
+ }
187
190
} ) ;
188
191
189
- it ( 'should be able handle mistake in banned characters array' , ( ) => {
192
+ it ( 'should be able to ban all numeric characters' , ( ) => {
193
+ const bannedChars = '0123456789' . split ( '' ) ;
194
+ const alphaText = faker . random . alphaNumeric ( 5 , {
195
+ bannedChars,
196
+ } ) ;
197
+
198
+ expect ( alphaText ) . toHaveLength ( 5 ) ;
199
+ for ( const bannedChar of bannedChars ) {
200
+ expect ( alphaText ) . not . includes ( bannedChar ) ;
201
+ }
202
+ } ) ;
203
+
204
+ it ( 'should be able to handle mistake in banned characters array' , ( ) => {
190
205
const alphaText = faker . random . alphaNumeric ( 5 , {
191
206
bannedChars : [ 'a' , 'p' , 'a' ] ,
192
207
} ) ;
193
208
194
209
expect ( alphaText ) . toHaveLength ( 5 ) ;
195
210
expect ( alphaText ) . match ( / [ b - o q - z ] / ) ;
196
211
} ) ;
212
+
213
+ it . todo ( 'should throw if all possible characters being banned' , ( ) => {
214
+ const bannedChars = 'abcdefghijklmnopqrstuvwxyz0123456789' . split ( '' ) ;
215
+ expect ( ( ) =>
216
+ faker . random . alphaNumeric ( 5 , {
217
+ bannedChars,
218
+ } )
219
+ ) . toThrowError ( ) ;
220
+ } ) ;
197
221
} ) ;
198
222
199
223
describe ( 'deprecation warnings' , ( ) => {
0 commit comments