File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -479,11 +479,17 @@ export class Random {
479479 'y' ,
480480 'z' ,
481481 ] ;
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 ) ;
486485 }
486+
487+ if ( charsArray . length === 0 ) {
488+ throw new Error (
489+ 'Unable to generate string, because all possible characters are banned.'
490+ ) ;
491+ }
492+
487493 for ( let i = 0 ; i < count ; i ++ ) {
488494 wholeString += this . faker . random . arrayElement ( charsArray ) ;
489495 }
Original file line number Diff line number Diff line change @@ -210,7 +210,7 @@ describe('random', () => {
210210 expect ( alphaText ) . match ( / [ b - o q - z ] / ) ;
211211 } ) ;
212212
213- it . todo ( 'should throw if all possible characters being banned' , ( ) => {
213+ it ( 'should throw if all possible characters being banned' , ( ) => {
214214 const bannedChars = 'abcdefghijklmnopqrstuvwxyz0123456789' . split ( '' ) ;
215215 expect ( ( ) =>
216216 faker . random . alphaNumeric ( 5 , {
You can’t perform that action at this time.
0 commit comments