Skip to content

Commit

Permalink
fix: test random.alphaNumeric (#517)
Browse files Browse the repository at this point in the history
Co-authored-by: Leyla Jähnig <[email protected]>
  • Loading branch information
xDivisionByZerox and Leyla Jähnig authored Feb 19, 2022
1 parent 9138ea0 commit 41ec6f0
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions test/random.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,23 +177,47 @@ 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'],
});

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', () => {
Expand Down

0 comments on commit 41ec6f0

Please sign in to comment.