diff options
| author | ST-DDT <[email protected]> | 2022-12-25 15:30:04 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-12-25 14:30:04 +0000 |
| commit | f0d2ffb256e5aefb98d4f38905ef081c8e6af43e (patch) | |
| tree | 4a4d6d5f3deca0af05910b0c961ea116e5386ceb /test | |
| parent | aa77888098add8bc5de5ed8f4f2dbc68aa7e8cef (diff) | |
| download | faker-f0d2ffb256e5aefb98d4f38905ef081c8e6af43e.tar.xz faker-f0d2ffb256e5aefb98d4f38905ef081c8e6af43e.zip | |
feat(helpers): allow empty string in fake (#1679)
Diffstat (limited to 'test')
| -rw-r--r-- | test/__snapshots__/helpers.spec.ts.snap | 6 | ||||
| -rw-r--r-- | test/helpers.spec.ts | 14 |
2 files changed, 13 insertions, 7 deletions
diff --git a/test/__snapshots__/helpers.spec.ts.snap b/test/__snapshots__/helpers.spec.ts.snap index 4ce31832..95ac4a03 100644 --- a/test/__snapshots__/helpers.spec.ts.snap +++ b/test/__snapshots__/helpers.spec.ts.snap @@ -33,6 +33,8 @@ exports[`helpers > 42 > fake > with a dynamic template 1`] = `"my string: Cky2ei exports[`helpers > 42 > fake > with a static template 1`] = `"my test string"`; +exports[`helpers > 42 > fake > with empty string 1`] = `""`; + exports[`helpers > 42 > fake > with multiple dynamic templates 1`] = `"Sandy"`; exports[`helpers > 42 > fake > with multiple static templates 1`] = `"B"`; @@ -216,6 +218,8 @@ exports[`helpers > 1211 > fake > with a dynamic template 1`] = `"my string: wKti exports[`helpers > 1211 > fake > with a static template 1`] = `"my test string"`; +exports[`helpers > 1211 > fake > with empty string 1`] = `""`; + exports[`helpers > 1211 > fake > with multiple dynamic templates 1`] = `"La Crosse"`; exports[`helpers > 1211 > fake > with multiple static templates 1`] = `"C"`; @@ -395,6 +399,8 @@ exports[`helpers > 1337 > fake > with a dynamic template 1`] = `"my string: 9U/4 exports[`helpers > 1337 > fake > with a static template 1`] = `"my test string"`; +exports[`helpers > 1337 > fake > with empty string 1`] = `""`; + exports[`helpers > 1337 > fake > with multiple dynamic templates 1`] = `"U/4:SK$>6Q"`; exports[`helpers > 1337 > fake > with multiple static templates 1`] = `"A"`; diff --git a/test/helpers.spec.ts b/test/helpers.spec.ts index 37a1bd02..2f591fc2 100644 --- a/test/helpers.spec.ts +++ b/test/helpers.spec.ts @@ -96,7 +96,8 @@ describe('helpers', () => { }); t.describe('fake', (t) => { - t.it('with a static template', 'my test string') + t.it('with empty string', '') + .it('with a static template', 'my test string') .it('with a dynamic template', 'my string: {{string.sample}}') .it('with multiple static templates', ['A', 'B', 'C']) .it('with multiple dynamic templates', [ @@ -555,6 +556,11 @@ describe('helpers', () => { }); describe('fake()', () => { + it('does allow empty string input', () => { + const actual = faker.helpers.fake(''); + expect(actual).toBe(''); + }); + it('replaces a token with a random value for a method without parentheses', () => { const actual = faker.helpers.fake('{{string.numeric}}'); expect(actual).toMatch(/^\d$/); @@ -602,12 +608,6 @@ describe('helpers', () => { expect(actual).toMatch(/^\d{5}$/); }); - it('does not allow empty string parameters', () => { - expect(() => faker.helpers.fake('')).toThrowError( - new FakerError('Pattern string cannot be empty.') - ); - }); - it('does not allow empty array parameters', () => { expect(() => faker.helpers.fake([])).toThrowError( new FakerError('Array of pattern strings cannot be empty.') |
