Skip to content

Commit 95b3e4d

Browse files
xDivisionByZeroxLeyla Jähnig
authored andcommitted
fix: test random.alphaNumeric (faker-js#517)
Co-authored-by: Leyla Jähnig <[email protected]>
1 parent 8522247 commit 95b3e4d

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

test/random.spec.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,23 +177,47 @@ describe('random', () => {
177177
expect(actual).toHaveLength(5);
178178
});
179179

180-
it('should be able to ban some characters', () => {
180+
it('should be able to ban all alphabetic characters', () => {
181+
const bannedChars = 'abcdefghijklmnopqrstuvwxyz'.split('');
181182
const alphaText = faker.random.alphaNumeric(5, {
182-
bannedChars: ['a', 'p'],
183+
bannedChars,
183184
});
184185

185186
expect(alphaText).toHaveLength(5);
186-
expect(alphaText).match(/[b-oq-z]/);
187+
for (const bannedChar of bannedChars) {
188+
expect(alphaText).not.includes(bannedChar);
189+
}
187190
});
188191

189-
it('should be able handle mistake in banned characters array', () => {
192+
it('should be able to ban all numeric characters', () => {
193+
const bannedChars = '0123456789'.split('');
194+
const alphaText = faker.random.alphaNumeric(5, {
195+
bannedChars,
196+
});
197+
198+
expect(alphaText).toHaveLength(5);
199+
for (const bannedChar of bannedChars) {
200+
expect(alphaText).not.includes(bannedChar);
201+
}
202+
});
203+
204+
it('should be able to handle mistake in banned characters array', () => {
190205
const alphaText = faker.random.alphaNumeric(5, {
191206
bannedChars: ['a', 'p', 'a'],
192207
});
193208

194209
expect(alphaText).toHaveLength(5);
195210
expect(alphaText).match(/[b-oq-z]/);
196211
});
212+
213+
it.todo('should throw if all possible characters being banned', () => {
214+
const bannedChars = 'abcdefghijklmnopqrstuvwxyz0123456789'.split('');
215+
expect(() =>
216+
faker.random.alphaNumeric(5, {
217+
bannedChars,
218+
})
219+
).toThrowError();
220+
});
197221
});
198222

199223
describe('deprecation warnings', () => {

0 commit comments

Comments
 (0)