diff options
| author | Robin van der Vliet <[email protected]> | 2023-09-15 21:48:17 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-09-15 19:48:17 +0000 |
| commit | 82b779da5e87fddd7b5a5564b7228ac54b44d349 (patch) | |
| tree | ed115b19bffa0a118abb551f52d2eadff5602beb /test | |
| parent | cb336641019f720a965e115678100e163c688b9f (diff) | |
| download | faker-82b779da5e87fddd7b5a5564b7228ac54b44d349.tar.xz faker-82b779da5e87fddd7b5a5564b7228ac54b44d349.zip | |
feat(location): Support ISO 3166-1 numeric country codes (#2325)
Diffstat (limited to 'test')
| -rw-r--r-- | test/modules/__snapshots__/location.spec.ts.snap | 36 | ||||
| -rw-r--r-- | test/modules/location.spec.ts | 27 |
2 files changed, 51 insertions, 12 deletions
diff --git a/test/modules/__snapshots__/location.spec.ts.snap b/test/modules/__snapshots__/location.spec.ts.snap index 6d693c9c..8324fab4 100644 --- a/test/modules/__snapshots__/location.spec.ts.snap +++ b/test/modules/__snapshots__/location.spec.ts.snap @@ -16,9 +16,17 @@ exports[`location > 42 > country 1`] = `"Guinea"`; exports[`location > 42 > countryCode > noArgs 1`] = `"GY"`; -exports[`location > 42 > countryCode > with alphaCode option 1`] = `"GUY"`; +exports[`location > 42 > countryCode > with string alpha-2 1`] = `"GY"`; -exports[`location > 42 > countryCode > with string 1`] = `"GY"`; +exports[`location > 42 > countryCode > with string alpha-3 1`] = `"GUY"`; + +exports[`location > 42 > countryCode > with string numeric 1`] = `"328"`; + +exports[`location > 42 > countryCode > with variant option alpha-2 1`] = `"GY"`; + +exports[`location > 42 > countryCode > with variant option alpha-3 1`] = `"GUY"`; + +exports[`location > 42 > countryCode > with variant option numeric 1`] = `"328"`; exports[`location > 42 > county 1`] = `"Borders"`; @@ -168,9 +176,17 @@ exports[`location > 1211 > country 1`] = `"Uganda"`; exports[`location > 1211 > countryCode > noArgs 1`] = `"UM"`; -exports[`location > 1211 > countryCode > with alphaCode option 1`] = `"UMI"`; +exports[`location > 1211 > countryCode > with string alpha-2 1`] = `"UM"`; + +exports[`location > 1211 > countryCode > with string alpha-3 1`] = `"UMI"`; + +exports[`location > 1211 > countryCode > with string numeric 1`] = `"581"`; -exports[`location > 1211 > countryCode > with string 1`] = `"UM"`; +exports[`location > 1211 > countryCode > with variant option alpha-2 1`] = `"UM"`; + +exports[`location > 1211 > countryCode > with variant option alpha-3 1`] = `"UMI"`; + +exports[`location > 1211 > countryCode > with variant option numeric 1`] = `"581"`; exports[`location > 1211 > county 1`] = `"Tyne and Wear"`; @@ -320,9 +336,17 @@ exports[`location > 1337 > country 1`] = `"Egypt"`; exports[`location > 1337 > countryCode > noArgs 1`] = `"EH"`; -exports[`location > 1337 > countryCode > with alphaCode option 1`] = `"ESH"`; +exports[`location > 1337 > countryCode > with string alpha-2 1`] = `"EH"`; + +exports[`location > 1337 > countryCode > with string alpha-3 1`] = `"ESH"`; + +exports[`location > 1337 > countryCode > with string numeric 1`] = `"732"`; + +exports[`location > 1337 > countryCode > with variant option alpha-2 1`] = `"EH"`; + +exports[`location > 1337 > countryCode > with variant option alpha-3 1`] = `"ESH"`; -exports[`location > 1337 > countryCode > with string 1`] = `"EH"`; +exports[`location > 1337 > countryCode > with variant option numeric 1`] = `"732"`; exports[`location > 1337 > county 1`] = `"Morgan County"`; diff --git a/test/modules/location.spec.ts b/test/modules/location.spec.ts index bd50c8ef..e363c188 100644 --- a/test/modules/location.spec.ts +++ b/test/modules/location.spec.ts @@ -74,8 +74,12 @@ describe('location', () => { t.describe('countryCode', (t) => { t.it('noArgs') - .it('with string', 'alpha-2') - .it('with alphaCode option', { variant: 'alpha-3' }); + .it('with string alpha-2', 'alpha-2') + .it('with string alpha-3', 'alpha-3') + .it('with string numeric', 'numeric') + .it('with variant option alpha-2', { variant: 'alpha-2' }) + .it('with variant option alpha-3', { variant: 'alpha-3' }) + .it('with variant option numeric', { variant: 'numeric' }); }); t.describeEach( @@ -152,14 +156,25 @@ describe('location', () => { 'random seeded tests for seed %i', () => { describe('countryCode()', () => { + it('returns random alpha-2 countryCode', () => { + const countryCode = faker.location.countryCode('alpha-2'); + + expect(countryCode).toBeTruthy(); + expect(countryCode).toMatch(/^[A-Z]{2}$/); + }); + it('returns random alpha-3 countryCode', () => { const countryCode = faker.location.countryCode('alpha-3'); expect(countryCode).toBeTruthy(); - expect( - countryCode.length, - 'The countryCode should be 3 characters long' - ).toBe(3); + expect(countryCode).toMatch(/^[A-Z]{3}$/); + }); + + it('returns random numeric countryCode', () => { + const countryCode = faker.location.countryCode('numeric'); + + expect(countryCode).toBeTruthy(); + expect(countryCode).toMatch(/^\d{3}$/); }); }); |
