-
-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add option to allow randCountryCode to generate alpha3 syntax codes (#…
…376) * feat: 🔥 add country code alpha3 option Country codes can be 2 or 3 chars long. This commit add alpha3 optionnal param to switch from default alpha2 to alpha3 syntax.
- Loading branch information
Showing
3 changed files
with
305 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { randCountryCode } from '../lib/country-code'; | ||
|
||
describe('countryCode', () => { | ||
it('should create default country code', () => { | ||
const result = randCountryCode(); | ||
|
||
expect(result.length).toBe(2); | ||
expect(typeof result).toBe('string'); | ||
}); | ||
|
||
it('should create default country code using alpha-3 syntax', () => { | ||
const result = randCountryCode({ alpha3: true }); | ||
|
||
expect(result.length).toBe(3); | ||
expect(typeof result).toBe('string'); | ||
}); | ||
|
||
it('should create array of default country codes', () => { | ||
const result = randCountryCode({ length: 10 }); | ||
|
||
expect(result.length).toBe(10); | ||
expect(Array.isArray(result)).toBe(true); | ||
expect(result[0].length).toBe(2); | ||
expect(result[0]).not.toEqual(result[1]); | ||
}); | ||
|
||
it('should create array of alpha3 country codes', () => { | ||
const result = randCountryCode({ length: 10, alpha3: true }); | ||
|
||
expect(result.length).toBe(10); | ||
expect(Array.isArray(result)).toBe(true); | ||
expect(result[0].length).toBe(3); | ||
expect(result[0]).not.toEqual(result[1]); | ||
}); | ||
}); |