File tree 2 files changed +11
-5
lines changed 2 files changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -479,11 +479,17 @@ export class Random {
479
479
'y' ,
480
480
'z' ,
481
481
] ;
482
- if ( options ) {
483
- if ( options . bannedChars ) {
484
- charsArray = arrayRemove ( charsArray , options . bannedChars ) ;
485
- }
482
+
483
+ if ( options . bannedChars ) {
484
+ charsArray = arrayRemove ( charsArray , options . bannedChars ) ;
486
485
}
486
+
487
+ if ( charsArray . length === 0 ) {
488
+ throw new Error (
489
+ 'Unable to generate string, because all possible characters are banned.'
490
+ ) ;
491
+ }
492
+
487
493
for ( let i = 0 ; i < count ; i ++ ) {
488
494
wholeString += this . faker . random . arrayElement ( charsArray ) ;
489
495
}
Original file line number Diff line number Diff line change @@ -210,7 +210,7 @@ describe('random', () => {
210
210
expect ( alphaText ) . match ( / [ b - o q - z ] / ) ;
211
211
} ) ;
212
212
213
- it . todo ( 'should throw if all possible characters being banned' , ( ) => {
213
+ it ( 'should throw if all possible characters being banned' , ( ) => {
214
214
const bannedChars = 'abcdefghijklmnopqrstuvwxyz0123456789' . split ( '' ) ;
215
215
expect ( ( ) =>
216
216
faker . random . alphaNumeric ( 5 , {
You can’t perform that action at this time.
0 commit comments