-
-
Notifications
You must be signed in to change notification settings - Fork 949
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 broken random.alphaNumeric() test #513
Comments
@Shinigami92 Do you want to fix it, or is it up for grabs? |
I will do this. No problem. |
Wouldn't it be easier to iterate over each banned character and expect the alpha text to not include it? Like this it('should be able to ban some characters', () => {
const bannedChars = ['a', 'p'];
const alphaText = faker.random.alphaNumeric(5, {
bannedChars,
});
expect(alphaText).toHaveLength(5);
for(const bannedChar of bannedChars) {
expect(alphaText.includes(bannedChar)).toBe(false);
}
}); This would allow changing the bannedChars Array without the need to rewrite the RegEx. |
IMO we should ban all characters As for "foreach vs regex": I think it's fine either way. @Shinigami92 Any preference? |
We could also force test this by splitting this into 2 tests. One with all alphabetic characters banned and one with all numbers characters baned. |
I really like that idea.
|
Should the current test with some characters baned (instead of all alpha/number) still be reworked or replaced by the 2 tests I suggested? Furthermore, what happens if a bannedChars Array with all alpha-numeric characters is provided? Should a test for that exist as well? |
Do you mean 2 tests:
|
The first one.
|
Yes. Although I assume, that this will reveal another "bug", that we can only fix in v6.1. If that's the case disable it with |
faker/test/random.spec.ts
Lines 180 to 187 in 431c108
faker/src/random.ts
Line 383 in 431c108
It just has a very low chance of failing (~0.2%).
The test should be fixed like this:
The same is true for the following test.
I also recommend to ban more chars, as the current test only has a chance of about ~25%(?) to actually the test the expected result.
Originally posted by @ST-DDT in #508 (comment)
The text was updated successfully, but these errors were encountered: