diff options
| author | ST-DDT <[email protected]> | 2022-10-23 20:32:47 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-10-23 18:32:47 +0000 |
| commit | 2eb253732ab4ee62552e153aded4901ad03e23b7 (patch) | |
| tree | 91704c0b618381463badb3ce0a5bcb7a26285aba /test | |
| parent | f4907a174dcb109b7e5d762ef6053caf0d9ad9d9 (diff) | |
| download | faker-2eb253732ab4ee62552e153aded4901ad03e23b7.tar.xz faker-2eb253732ab4ee62552e153aded4901ad03e23b7.zip | |
feat: fake with multiple parameters (#1459)
Diffstat (limited to 'test')
| -rw-r--r-- | test/helpers.spec.ts | 48 |
1 files changed, 34 insertions, 14 deletions
diff --git a/test/helpers.spec.ts b/test/helpers.spec.ts index 8f430e9b..39aa1982 100644 --- a/test/helpers.spec.ts +++ b/test/helpers.spec.ts @@ -488,31 +488,51 @@ describe('helpers', () => { }); describe('fake()', () => { - it('replaces a token with a random value for a method with no parameters', () => { - const name = faker.helpers.fake('{{phone.number}}'); - expect(name).toMatch(/\d/); + it('replaces a token with a random value for a method without parentheses', () => { + const actual = faker.helpers.fake('{{string.numeric}}'); + expect(actual).toMatch(/^\d$/); }); - it('replaces multiple tokens with random values for methods with no parameters', () => { - const name = faker.helpers.fake( - '{{helpers.arrayElement}}{{helpers.arrayElement}}{{helpers.arrayElement}}' + it('replaces multiple tokens with random values for methods without parentheses', () => { + const actual = faker.helpers.fake( + '{{string.numeric}}{{string.numeric}}{{string.numeric}}' ); - expect(name).toMatch(/[abc]{3}/); + expect(actual).toMatch(/^\d{3}$/); }); - it('replaces a token with a random value for a methods with a simple parameter', () => { - const random = faker.helpers.fake( - '{{helpers.slugify("Will This Work")}}' - ); - expect(random).toBe('Will-This-Work'); + it('replaces a token with a random value for a method with empty parentheses', () => { + const actual = faker.helpers.fake('{{string.numeric()}}'); + expect(actual).toMatch(/^\d$/); + }); + + it('replaces a token with a random value for a method with an unquoted parameter', () => { + const random = faker.helpers.fake('{{helpers.slugify(This Works)}}'); + expect(random).toBe('This-Works'); + }); + + it('replaces a token with a random value for a method with a simple parameter', () => { + const actual = faker.helpers.fake('{{string.numeric(3)}}'); + expect(actual).toMatch(/^\d{3}$/); }); it('replaces a token with a random value for a method with an array parameter', () => { const arr = ['one', 'two', 'three']; - const random = faker.helpers.fake( + const actual = faker.helpers.fake( '{{helpers.arrayElement(["one", "two", "three"])}}' ); - expect(arr).toContain(random); + expect(arr).toContain(actual); + }); + + it('replaces a token with a random value for a method with an object parameter', () => { + const actual = faker.helpers.fake('{{random.alpha({"count": 3})}}'); + expect(actual).toMatch(/^[a-z]{3}$/i); + }); + + it('replaces a token with a random value for a method with multiple parameters', () => { + const actual = faker.helpers.fake( + '{{string.numeric(5, {"allowLeadingZeros": true})}}' + ); + expect(actual).toMatch(/^\d{5}$/); }); it('does not allow undefined parameters', () => { |
