File tree 3 files changed +13
-5
lines changed
3 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -543,7 +543,7 @@ export class HelpersModule {
543
543
*/
544
544
fake ( str : string ) : string {
545
545
// if incoming str parameter is not provided, return error message
546
- if ( typeof str !== 'string' || str . length === 0 ) {
546
+ if ( typeof str !== 'string' ) {
547
547
throw new FakerError ( 'string parameter is required!' ) ;
548
548
}
549
549
@@ -617,10 +617,6 @@ export class HelpersModule {
617
617
// We cannot use string.replace here because the result might contain evaluated characters
618
618
const res = str . substring ( 0 , start ) + result + str . substring ( end + 2 ) ;
619
619
620
- if ( res === '' ) {
621
- return '' ;
622
- }
623
-
624
620
// return the response recursively until we are done finding all tags
625
621
return this . fake ( res ) ;
626
622
}
Original file line number Diff line number Diff line change @@ -31,6 +31,8 @@ exports[`helpers > 42 > arrayElements > with array and count 1`] = `
31
31
32
32
exports [` helpers > 42 > fake > with args 1` ] = ` "my string: Cky2eiXX/J"` ;
33
33
34
+ exports [` helpers > 42 > fake > with empty string 1` ] = ` ""` ;
35
+
34
36
exports [` helpers > 42 > fake > with plain string 1` ] = ` "my test string"` ;
35
37
36
38
exports [` helpers > 42 > maybe > with only value 1` ] = ` "Hello World!"` ;
@@ -210,6 +212,8 @@ exports[`helpers > 1211 > arrayElements > with array and count 1`] = `
210
212
211
213
exports [` helpers > 1211 > fake > with args 1` ] = ` "my string: wKti5-}$_/"` ;
212
214
215
+ exports [` helpers > 1211 > fake > with empty string 1` ] = ` ""` ;
216
+
213
217
exports [` helpers > 1211 > fake > with plain string 1` ] = ` "my test string"` ;
214
218
215
219
exports [` helpers > 1211 > maybe > with only value 1` ] = ` undefined` ;
@@ -385,6 +389,8 @@ exports[`helpers > 1337 > arrayElements > with array and count 1`] = `
385
389
386
390
exports [` helpers > 1337 > fake > with args 1` ] = ` "my string: 9U/4:SK$>6"` ;
387
391
392
+ exports [` helpers > 1337 > fake > with empty string 1` ] = ` ""` ;
393
+
388
394
exports [` helpers > 1337 > fake > with plain string 1` ] = ` "my test string"` ;
389
395
390
396
exports [` helpers > 1337 > maybe > with only value 1` ] = ` "Hello World!"` ;
Original file line number Diff line number Diff line change @@ -96,6 +96,7 @@ describe('helpers', () => {
96
96
} ) ;
97
97
98
98
t . describe ( 'fake' , ( t ) => {
99
+ t . it ( 'with empty string' , '' ) ;
99
100
t . it ( 'with plain string' , 'my test string' ) . it (
100
101
'with args' ,
101
102
'my string: {{datatype.string}}'
@@ -551,6 +552,11 @@ describe('helpers', () => {
551
552
} ) ;
552
553
553
554
describe ( 'fake()' , ( ) => {
555
+ it ( 'should take an empty string' , ( ) => {
556
+ const actual = faker . helpers . fake ( '' ) ;
557
+ expect ( actual ) . toBe ( '' ) ;
558
+ } ) ;
559
+
554
560
it ( 'replaces a token with a random value for a method without parentheses' , ( ) => {
555
561
const actual = faker . helpers . fake ( '{{string.numeric}}' ) ;
556
562
expect ( actual ) . toMatch ( / ^ \d $ / ) ;
You can’t perform that action at this time.
0 commit comments