From 5e2ad9893375352bbf626cc87712fbd4d7a45e94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leyla=20J=C3=A4hnig?= Date: Sat, 19 Feb 2022 14:38:14 +0100 Subject: [PATCH 1/6] fix: alphaNumeric test case --- test/random.spec.ts | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/test/random.spec.ts b/test/random.spec.ts index 09a003f8dd6..b7ccf25637a 100644 --- a/test/random.spec.ts +++ b/test/random.spec.ts @@ -177,13 +177,30 @@ 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]/); + expect(alphaText).match(/^[0-9]{5}$/); + for (const bannedChar of bannedChars) { + expect(alphaText.includes(bannedChar)).toBe(false); + } + }); + + it('should be able to ban all numeric characters', () => { + const bannedChars = '0123456789'.split(''); + const alphaText = faker.random.alphaNumeric(5, { + bannedChars, + }); + + expect(alphaText).toHaveLength(5); + expect(alphaText).match(/^[a-z]{5}$/); + for (const bannedChar of bannedChars) { + expect(alphaText.includes(bannedChar)).toBe(false); + } }); it('should be able handle mistake in banned characters array', () => { From aafefa17a02b3b6d387f616a8b29237c84e627c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leyla=20J=C3=A4hnig?= Date: Sat, 19 Feb 2022 14:42:11 +0100 Subject: [PATCH 2/6] fix: typo in test description --- test/random.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/random.spec.ts b/test/random.spec.ts index b7ccf25637a..09ba81ce30a 100644 --- a/test/random.spec.ts +++ b/test/random.spec.ts @@ -203,7 +203,7 @@ describe('random', () => { } }); - it('should be able handle mistake in banned characters array', () => { + it('should be able to handle mistake in banned characters array', () => { const alphaText = faker.random.alphaNumeric(5, { bannedChars: ['a', 'p', 'a'], }); From d47f860991ff7b61b39fd6a8881f10f19f4c377f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leyla=20J=C3=A4hnig?= Date: Sat, 19 Feb 2022 14:45:29 +0100 Subject: [PATCH 3/6] feat: add unhandled test case idea --- test/random.spec.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/random.spec.ts b/test/random.spec.ts index 09ba81ce30a..d889b0e5600 100644 --- a/test/random.spec.ts +++ b/test/random.spec.ts @@ -211,6 +211,8 @@ describe('random', () => { expect(alphaText).toHaveLength(5); expect(alphaText).match(/[b-oq-z]/); }); + + it.todo('should be able to handle all possible characters being banned'); }); describe('deprecation warnings', () => { From b2f17eb643ec81e9d4d5a7e7fe731739300b3f86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leyla=20J=C3=A4hnig?= Date: Sat, 19 Feb 2022 17:05:02 +0100 Subject: [PATCH 4/6] test: implement alphaNumeric error test case --- test/random.spec.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/random.spec.ts b/test/random.spec.ts index d889b0e5600..a6672d00258 100644 --- a/test/random.spec.ts +++ b/test/random.spec.ts @@ -212,7 +212,14 @@ describe('random', () => { expect(alphaText).match(/[b-oq-z]/); }); - it.todo('should be able to handle all possible characters being banned'); + it.todo('should throw if all possible characters being banned', () => { + const bannedChars = 'abcdefghijklmnopqrstuvwxyz0123456789'.split(''); + expect(() => + faker.random.alphaNumeric(5, { + bannedChars, + }) + ).toThrowError(); + }); }); describe('deprecation warnings', () => { From b46a68f75e5f4763b583b6ea2afbe34b4eed8d72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leyla=20J=C3=A4hnig?= Date: Sat, 19 Feb 2022 20:07:38 +0100 Subject: [PATCH 5/6] refactor: rewrite expect statements --- test/random.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/random.spec.ts b/test/random.spec.ts index a6672d00258..e4104abe557 100644 --- a/test/random.spec.ts +++ b/test/random.spec.ts @@ -186,7 +186,7 @@ describe('random', () => { expect(alphaText).toHaveLength(5); expect(alphaText).match(/^[0-9]{5}$/); for (const bannedChar of bannedChars) { - expect(alphaText.includes(bannedChar)).toBe(false); + expect(alphaText).not.includes(bannedChar); } }); @@ -199,7 +199,7 @@ describe('random', () => { expect(alphaText).toHaveLength(5); expect(alphaText).match(/^[a-z]{5}$/); for (const bannedChar of bannedChars) { - expect(alphaText.includes(bannedChar)).toBe(false); + expect(alphaText).not.includes(bannedChar); } }); From 39536e85743ea0c469023bcded7d283530de916b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leyla=20J=C3=A4hnig?= Date: Sat, 19 Feb 2022 22:09:08 +0100 Subject: [PATCH 6/6] refactor: rewrite alphaNumeric test to use for loop --- test/random.spec.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/random.spec.ts b/test/random.spec.ts index e4104abe557..e969817f26c 100644 --- a/test/random.spec.ts +++ b/test/random.spec.ts @@ -184,7 +184,6 @@ describe('random', () => { }); expect(alphaText).toHaveLength(5); - expect(alphaText).match(/^[0-9]{5}$/); for (const bannedChar of bannedChars) { expect(alphaText).not.includes(bannedChar); } @@ -197,7 +196,6 @@ describe('random', () => { }); expect(alphaText).toHaveLength(5); - expect(alphaText).match(/^[a-z]{5}$/); for (const bannedChar of bannedChars) { expect(alphaText).not.includes(bannedChar); }