diff options
| author | Eric Cheng <[email protected]> | 2022-11-14 17:56:49 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-11-14 22:56:49 +0000 |
| commit | 801e9e0a6afa2bd472652eb7aaee5581ef458342 (patch) | |
| tree | e33cf4d8682583164606e62d49876806664eb9d2 /test/string.spec.ts | |
| parent | 66ccca3e11721647c4c13179eb1e23f13d43ef03 (diff) | |
| download | faker-801e9e0a6afa2bd472652eb7aaee5581ef458342.tar.xz faker-801e9e0a6afa2bd472652eb7aaee5581ef458342.zip | |
refactor(string): rename params (#1551)
Diffstat (limited to 'test/string.spec.ts')
| -rw-r--r-- | test/string.spec.ts | 124 |
1 files changed, 62 insertions, 62 deletions
diff --git a/test/string.spec.ts b/test/string.spec.ts index 66c6bc59..6d34f098 100644 --- a/test/string.spec.ts +++ b/test/string.spec.ts @@ -14,11 +14,11 @@ describe('string', () => { .it('with casing = lower', { casing: 'lower' }) .it('with casing = upper', { casing: 'upper' }) .it('with casing = mixed', { casing: 'mixed' }) - .it('with bannedChars', { bannedChars: 'abcdefghijk' }) - .it('with length, casing and bannedChars', { + .it('with exclude', { exclude: 'abcdefghijk' }) + .it('with length, casing and exclude', { length: 7, casing: 'lower', - bannedChars: 'lmnopqrstu', + exclude: 'lmnopqrstu', }); }); @@ -29,11 +29,11 @@ describe('string', () => { .it('with casing = lower', { casing: 'lower' }) .it('with casing = upper', { casing: 'upper' }) .it('with casing = mixed', { casing: 'mixed' }) - .it('with bannedChars', { bannedChars: 'abcdefghijk12345' }) - .it('with length, casing and bannedChars', { + .it('with exclude', { exclude: 'abcdefghijk12345' }) + .it('with length, casing and exclude', { length: 7, casing: 'lower', - bannedChars: 'lmnopqrstu67890', + exclude: 'lmnopqrstu67890', }); }); @@ -56,11 +56,11 @@ describe('string', () => { .itRepeated('with length parameter', 5, 5) .it('with length', { length: 6 }) .it('with allowLeadingZeros', { allowLeadingZeros: true }) - .it('with bannedDigits', { bannedDigits: '12345' }) - .it('with length, allowLeadingZeros and bannedDigits', { + .it('with exclude', { exclude: '12345' }) + .it('with length, allowLeadingZeros and exclude', { length: 7, allowLeadingZeros: true, - bannedDigits: '12345', + exclude: '12345', }); }); @@ -114,7 +114,7 @@ describe('string', () => { const actual = faker.string.alpha({ length: 5, casing: 'lower', - bannedChars: ['a', 'p'], + exclude: ['a', 'p'], }); expect(actual).toHaveLength(5); @@ -125,35 +125,35 @@ describe('string', () => { const actual = faker.string.alpha({ length: 5, casing: 'lower', - bannedChars: 'ap', + exclude: 'ap', }); expect(actual).toHaveLength(5); expect(actual).toMatch(/^[b-oq-z]{5}$/); }); - it('should be able handle mistake in banned characters array', () => { + it('should be able handle mistake in excluded characters array', () => { const alphaText = faker.string.alpha({ length: 5, casing: 'lower', - bannedChars: ['a', 'a', 'p'], + exclude: ['a', 'a', 'p'], }); expect(alphaText).toHaveLength(5); expect(alphaText).toMatch(/^[b-oq-z]{5}$/); }); - it('should throw if all possible characters being banned', () => { - const bannedChars = 'abcdefghijklmnopqrstuvwxyz'.split(''); + it('should throw if all possible characters being excluded', () => { + const exclude = 'abcdefghijklmnopqrstuvwxyz'.split(''); expect(() => faker.string.alpha({ length: 5, casing: 'lower', - bannedChars, + exclude, }) ).toThrowError( new FakerError( - 'Unable to generate string, because all possible characters are banned.' + 'Unable to generate string, because all possible characters are excluded.' ) ); }); @@ -162,15 +162,15 @@ describe('string', () => { const input: { length: number; casing: 'mixed'; - bannedChars: string[]; + exclude: string[]; } = Object.freeze({ length: 5, casing: 'mixed', - bannedChars: ['a', '%'], + exclude: ['a', '%'], }); expect(() => faker.string.alpha(input)).not.toThrow(); - expect(input.bannedChars).toEqual(['a', '%']); + expect(input.exclude).toEqual(['a', '%']); }); }); @@ -206,92 +206,92 @@ describe('string', () => { ); it('should be able to ban all alphabetic characters', () => { - const bannedChars = 'abcdefghijklmnopqrstuvwxyz'.split(''); + const exclude = 'abcdefghijklmnopqrstuvwxyz'.split(''); const alphaText = faker.string.alphanumeric({ length: 5, casing: 'lower', - bannedChars, + exclude, }); expect(alphaText).toHaveLength(5); - for (const bannedChar of bannedChars) { - expect(alphaText).not.includes(bannedChar); + for (const excludedChar of exclude) { + expect(alphaText).not.includes(excludedChar); } }); it('should be able to ban all alphabetic characters via string', () => { - const bannedChars = 'abcdefghijklmnopqrstuvwxyz'; + const exclude = 'abcdefghijklmnopqrstuvwxyz'; const alphaText = faker.string.alphanumeric({ length: 5, casing: 'lower', - bannedChars, + exclude, }); expect(alphaText).toHaveLength(5); - for (const bannedChar of bannedChars) { - expect(alphaText).not.includes(bannedChar); + for (const excludedChar of exclude) { + expect(alphaText).not.includes(excludedChar); } }); it('should be able to ban all numeric characters', () => { - const bannedChars = '0123456789'.split(''); + const exclude = '0123456789'.split(''); const alphaText = faker.string.alphanumeric({ length: 5, - bannedChars, + exclude, }); expect(alphaText).toHaveLength(5); - for (const bannedChar of bannedChars) { - expect(alphaText).not.includes(bannedChar); + for (const excludedChar of exclude) { + expect(alphaText).not.includes(excludedChar); } }); it('should be able to ban all numeric characters via string', () => { - const bannedChars = '0123456789'; + const exclude = '0123456789'; const alphaText = faker.string.alphanumeric({ length: 5, - bannedChars, + exclude, }); expect(alphaText).toHaveLength(5); - for (const bannedChar of bannedChars) { - expect(alphaText).not.includes(bannedChar); + for (const excludedChar of exclude) { + expect(alphaText).not.includes(excludedChar); } }); - it('should be able to handle mistake in banned characters array', () => { + it('should be able to handle mistake in excluded characters array', () => { const alphaText = faker.string.alphanumeric({ length: 5, casing: 'lower', - bannedChars: ['a', 'p', 'a'], + exclude: ['a', 'p', 'a'], }); expect(alphaText).toHaveLength(5); expect(alphaText).toMatch(/^[0-9b-oq-z]{5}$/); }); - it('should throw if all possible characters being banned', () => { - const bannedChars = 'abcdefghijklmnopqrstuvwxyz0123456789'.split(''); + it('should throw if all possible characters being excluded', () => { + const exclude = 'abcdefghijklmnopqrstuvwxyz0123456789'.split(''); expect(() => faker.string.alphanumeric({ length: 5, casing: 'lower', - bannedChars, + exclude, }) ).toThrowError( new FakerError( - 'Unable to generate string, because all possible characters are banned.' + 'Unable to generate string, because all possible characters are excluded.' ) ); }); - it('should throw if all possible characters being banned via string', () => { - const bannedChars = 'abcdefghijklmnopqrstuvwxyz0123456789'; + it('should throw if all possible characters being excluded via string', () => { + const exclude = 'abcdefghijklmnopqrstuvwxyz0123456789'; expect(() => faker.string.alphanumeric({ length: 5, casing: 'lower', - bannedChars, + exclude, }) ).toThrowError(); }); @@ -299,14 +299,14 @@ describe('string', () => { it('should not mutate the input object', () => { const input: { length: number; - bannedChars: string[]; + exclude: string[]; } = Object.freeze({ length: 5, - bannedChars: ['a', '0', '%'], + exclude: ['a', '0', '%'], }); expect(() => faker.string.alphanumeric(input)).not.toThrow(); - expect(input.bannedChars).toEqual(['a', '0', '%']); + expect(input.exclude).toEqual(['a', '0', '%']); }); }); @@ -374,68 +374,68 @@ describe('string', () => { expect(actual).toMatch(/^[0-9]+$/); }); - it('should allow leading zeros via option and all other digits banned', () => { + it('should allow leading zeros via option and all other digits excluded', () => { const actual = faker.string.numeric({ length: 4, allowLeadingZeros: true, - bannedDigits: '123456789'.split(''), + exclude: '123456789'.split(''), }); expect(actual).toBe('0000'); }); - it('should allow leading zeros via option and all other digits banned via string', () => { + it('should allow leading zeros via option and all other digits excluded via string', () => { const actual = faker.string.numeric({ length: 4, allowLeadingZeros: true, - bannedDigits: '123456789', + exclude: '123456789', }); expect(actual).toBe('0000'); }); - it('should fail on leading zeros via option and all other digits banned', () => { + it('should fail on leading zeros via option and all other digits excluded', () => { expect(() => faker.string.numeric({ length: 4, allowLeadingZeros: false, - bannedDigits: '123456789'.split(''), + exclude: '123456789'.split(''), }) ).toThrowError( new FakerError( - 'Unable to generate numeric string, because all possible digits are banned.' + 'Unable to generate numeric string, because all possible digits are excluded.' ) ); }); - it('should fail on leading zeros via option and all other digits banned via string', () => { + it('should fail on leading zeros via option and all other digits excluded via string', () => { expect(() => faker.string.numeric({ length: 4, allowLeadingZeros: false, - bannedDigits: '123456789', + exclude: '123456789', }) ).toThrowError( new FakerError( - 'Unable to generate numeric string, because all possible digits are banned.' + 'Unable to generate numeric string, because all possible digits are excluded.' ) ); }); - it('should ban all digits passed via bannedDigits', () => { + it('should ban all digits passed via exclude', () => { const actual = faker.string.numeric({ length: 1000, - bannedDigits: 'c84U1'.split(''), + exclude: 'c84U1'.split(''), }); expect(actual).toHaveLength(1000); expect(actual).toMatch(/^[0235679]{1000}$/); }); - it('should ban all digits passed via bannedDigits via string', () => { + it('should ban all digits passed via exclude via string', () => { const actual = faker.string.numeric({ length: 1000, - bannedDigits: 'c84U1', + exclude: 'c84U1', }); expect(actual).toHaveLength(1000); |
