Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: test random.alphaNumeric #517

Merged
merged 6 commits into from
Feb 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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