@@ -177,23 +177,47 @@ describe('random', () => {
177177 expect ( actual ) . toHaveLength ( 5 ) ;
178178 } ) ;
179179
180- it ( 'should be able to ban some characters' , ( ) => {
180+ it ( 'should be able to ban all alphabetic characters' , ( ) => {
181+ const bannedChars = 'abcdefghijklmnopqrstuvwxyz' . split ( '' ) ;
181182 const alphaText = faker . random . alphaNumeric ( 5 , {
182- bannedChars : [ 'a' , 'p' ] ,
183+ bannedChars,
183184 } ) ;
184185
185186 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+ }
187190 } ) ;
188191
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' , ( ) => {
190205 const alphaText = faker . random . alphaNumeric ( 5 , {
191206 bannedChars : [ 'a' , 'p' , 'a' ] ,
192207 } ) ;
193208
194209 expect ( alphaText ) . toHaveLength ( 5 ) ;
195210 expect ( alphaText ) . match ( / [ b - o q - z ] / ) ;
196211 } ) ;
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+ } ) ;
197221 } ) ;
198222
199223 describe ( 'deprecation warnings' , ( ) => {
0 commit comments