diff options
| author | ST-DDT <[email protected]> | 2022-05-07 10:25:37 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-05-07 08:25:37 +0000 |
| commit | a60d5e3ea3d1109b90cbb51d8a4a10aba2290ada (patch) | |
| tree | bb3dbbfe9dc7c3659b61631418b74208be7210d0 /test | |
| parent | f2c3a39563c706129ff5622c21fe3168707be77b (diff) | |
| download | faker-a60d5e3ea3d1109b90cbb51d8a4a10aba2290ada.tar.xz faker-a60d5e3ea3d1109b90cbb51d8a4a10aba2290ada.zip | |
feat: support locale definitions directly from faker.fake (#884)
Diffstat (limited to 'test')
| -rw-r--r-- | test/fake.spec.ts | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/test/fake.spec.ts b/test/fake.spec.ts index 2846b9ee..c9ce3b31 100644 --- a/test/fake.spec.ts +++ b/test/fake.spec.ts @@ -38,13 +38,33 @@ describe('fake', () => { it('does not allow invalid module name', () => { expect(() => faker.fake('{{foo.bar}}')).toThrowError( - new FakerError('Invalid module: foo') + new FakerError(`Invalid module method or definition: foo.bar +- faker.foo.bar is not a function +- faker.definitions.foo.bar is not an array`) + ); + }); + + it('does not allow missing method name', () => { + expect(() => faker.fake('{{address}}')).toThrowError( + new FakerError(`Invalid module method or definition: address +- faker.address is not a function +- faker.definitions.address is not an array`) ); }); it('does not allow invalid method name', () => { expect(() => faker.fake('{{address.foo}}')).toThrowError( - new FakerError('Invalid method: address.foo') + new FakerError(`Invalid module method or definition: address.foo +- faker.address.foo is not a function +- faker.definitions.address.foo is not an array`) + ); + }); + + it('does not allow invalid definitions data', () => { + expect(() => faker.fake('{{finance.credit_card}}')).toThrowError( + new FakerError(`Invalid module method or definition: finance.credit_card +- faker.finance.credit_card is not a function +- faker.definitions.finance.credit_card is not an array`) ); }); @@ -52,6 +72,18 @@ describe('fake', () => { expect(faker.fake('{{helpers.repeatString}}')).toBe(''); }); + it('should be able to return locale definition strings', () => { + expect(faker.definitions.cell_phone.formats).toContain( + faker.fake('{{cell_phone.formats}}') + ); + }); + + it('should be able to return locale definition strings that starts with the name of an existing module', () => { + expect(faker.definitions.address.city_name).toContain( + faker.fake('{{address.city_name}}') + ); + }); + it('should be able to handle only {{ brackets', () => { expect(faker.fake('{{hello')).toBe('{{hello'); expect(faker.fake('hello{{')).toBe('hello{{'); |
