diff options
| author | Leyla Jähnig <[email protected]> | 2022-02-19 23:18:29 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-02-19 23:18:29 +0100 |
| commit | 41ec6f08784afc2a674568328a0ea2bfb033a411 (patch) | |
| tree | 875433e59072fefc1102a6c122cb1b2813a3d50e /test | |
| parent | 9138ea0fb7ca7d0247588eec7a7c8a7a3cfbbb37 (diff) | |
| download | faker-41ec6f08784afc2a674568328a0ea2bfb033a411.tar.xz faker-41ec6f08784afc2a674568328a0ea2bfb033a411.zip | |
fix: test random.alphaNumeric (#517)
Co-authored-by: Leyla Jähnig <[email protected]>
Diffstat (limited to 'test')
| -rw-r--r-- | test/random.spec.ts | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/test/random.spec.ts b/test/random.spec.ts index 09a003f8..e969817f 100644 --- a/test/random.spec.ts +++ b/test/random.spec.ts @@ -177,16 +177,31 @@ describe('random', () => { expect(actual).toHaveLength(5); }); - it('should be able to ban some characters', () => { + it('should be able to ban all alphabetic characters', () => { + const bannedChars = 'abcdefghijklmnopqrstuvwxyz'.split(''); const alphaText = faker.random.alphaNumeric(5, { - bannedChars: ['a', 'p'], + bannedChars, }); expect(alphaText).toHaveLength(5); - expect(alphaText).match(/[b-oq-z]/); + for (const bannedChar of bannedChars) { + expect(alphaText).not.includes(bannedChar); + } }); - it('should be able handle mistake in banned characters array', () => { + it('should be able to ban all numeric characters', () => { + const bannedChars = '0123456789'.split(''); + const alphaText = faker.random.alphaNumeric(5, { + bannedChars, + }); + + expect(alphaText).toHaveLength(5); + for (const bannedChar of bannedChars) { + expect(alphaText).not.includes(bannedChar); + } + }); + + it('should be able to handle mistake in banned characters array', () => { const alphaText = faker.random.alphaNumeric(5, { bannedChars: ['a', 'p', 'a'], }); @@ -194,6 +209,15 @@ describe('random', () => { expect(alphaText).toHaveLength(5); expect(alphaText).match(/[b-oq-z]/); }); + + it.todo('should throw if all possible characters being banned', () => { + const bannedChars = 'abcdefghijklmnopqrstuvwxyz0123456789'.split(''); + expect(() => + faker.random.alphaNumeric(5, { + bannedChars, + }) + ).toThrowError(); + }); }); describe('deprecation warnings', () => { |
