@@ -488,31 +488,51 @@ describe('helpers', () => {
488488 } ) ;
489489
490490 describe ( 'fake()' , ( ) => {
491- it ( 'replaces a token with a random value for a method with no parameters ' , ( ) => {
492- const name = faker . helpers . fake ( '{{phone.number }}' ) ;
493- expect ( name ) . toMatch ( / \d / ) ;
491+ it ( 'replaces a token with a random value for a method without parentheses ' , ( ) => {
492+ const actual = faker . helpers . fake ( '{{string.numeric }}' ) ;
493+ expect ( actual ) . toMatch ( / ^ \d $ / ) ;
494494 } ) ;
495495
496- it ( 'replaces multiple tokens with random values for methods with no parameters ' , ( ) => {
497- const name = faker . helpers . fake (
498- '{{helpers.arrayElement }}{{helpers.arrayElement }}{{helpers.arrayElement }}'
496+ it ( 'replaces multiple tokens with random values for methods without parentheses ' , ( ) => {
497+ const actual = faker . helpers . fake (
498+ '{{string.numeric }}{{string.numeric }}{{string.numeric }}'
499499 ) ;
500- expect ( name ) . toMatch ( / [ a b c ] { 3 } / ) ;
500+ expect ( actual ) . toMatch ( / ^ \d { 3 } $ / ) ;
501501 } ) ;
502502
503- it ( 'replaces a token with a random value for a methods with a simple parameter' , ( ) => {
504- const random = faker . helpers . fake (
505- '{{helpers.slugify("Will This Work")}}'
506- ) ;
507- expect ( random ) . toBe ( 'Will-This-Work' ) ;
503+ it ( 'replaces a token with a random value for a method with empty parentheses' , ( ) => {
504+ const actual = faker . helpers . fake ( '{{string.numeric()}}' ) ;
505+ expect ( actual ) . toMatch ( / ^ \d $ / ) ;
506+ } ) ;
507+
508+ it ( 'replaces a token with a random value for a method with an unquoted parameter' , ( ) => {
509+ const random = faker . helpers . fake ( '{{helpers.slugify(This Works)}}' ) ;
510+ expect ( random ) . toBe ( 'This-Works' ) ;
511+ } ) ;
512+
513+ it ( 'replaces a token with a random value for a method with a simple parameter' , ( ) => {
514+ const actual = faker . helpers . fake ( '{{string.numeric(3)}}' ) ;
515+ expect ( actual ) . toMatch ( / ^ \d { 3 } $ / ) ;
508516 } ) ;
509517
510518 it ( 'replaces a token with a random value for a method with an array parameter' , ( ) => {
511519 const arr = [ 'one' , 'two' , 'three' ] ;
512- const random = faker . helpers . fake (
520+ const actual = faker . helpers . fake (
513521 '{{helpers.arrayElement(["one", "two", "three"])}}'
514522 ) ;
515- expect ( arr ) . toContain ( random ) ;
523+ expect ( arr ) . toContain ( actual ) ;
524+ } ) ;
525+
526+ it ( 'replaces a token with a random value for a method with an object parameter' , ( ) => {
527+ const actual = faker . helpers . fake ( '{{random.alpha({"count": 3})}}' ) ;
528+ expect ( actual ) . toMatch ( / ^ [ a - z ] { 3 } $ / i) ;
529+ } ) ;
530+
531+ it ( 'replaces a token with a random value for a method with multiple parameters' , ( ) => {
532+ const actual = faker . helpers . fake (
533+ '{{string.numeric(5, {"allowLeadingZeros": true})}}'
534+ ) ;
535+ expect ( actual ) . toMatch ( / ^ \d { 5 } $ / ) ;
516536 } ) ;
517537
518538 it ( 'does not allow undefined parameters' , ( ) => {
0 commit comments