aboutsummaryrefslogtreecommitdiff
path: root/test/string.spec.ts
diff options
context:
space:
mode:
authorLeyla Jähnig <[email protected]>2023-01-09 19:59:37 +0100
committerGitHub <[email protected]>2023-01-09 19:59:37 +0100
commit099e76ce0fb180beb5fd62d72a07c236e04cdca0 (patch)
treea3b082a09579679ef371b0704e5b87f307cdaff5 /test/string.spec.ts
parent27dff93aa27d755874aa5022c78f17ff8e9cf7e0 (diff)
downloadfaker-099e76ce0fb180beb5fd62d72a07c236e04cdca0.tar.xz
faker-099e76ce0fb180beb5fd62d72a07c236e04cdca0.zip
feat(string): nanoid (#1716)
Diffstat (limited to 'test/string.spec.ts')
-rw-r--r--test/string.spec.ts31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/string.spec.ts b/test/string.spec.ts
index c9f82593..1ad429ca 100644
--- a/test/string.spec.ts
+++ b/test/string.spec.ts
@@ -98,6 +98,12 @@ describe('string', () => {
t.itRepeated('uuid', 5);
+ t.describe('nanoid', (t) => {
+ t.itRepeated('noArgs', 5)
+ .it('with length parameter', 30)
+ .it('with length range', { min: 13, max: 37 });
+ });
+
t.describe('special', (t) => {
t.it('noArgs')
.itRepeated('with length parameter', 5, 5)
@@ -657,6 +663,31 @@ describe('string', () => {
});
});
+ describe(`nanoid`, () => {
+ it('generates a valid Nano ID', () => {
+ const id = faker.string.nanoid();
+ const regex = /^[0-9a-zA-Z_-]+$/;
+ expect(id).toMatch(regex);
+ });
+
+ it('should have a default length of 21', () => {
+ const id = faker.string.nanoid();
+ expect(id).toHaveLength(21);
+ });
+
+ it('should return an empty string when length is negative', () => {
+ const id = faker.string.nanoid(-1);
+ expect(id).toBe('');
+ });
+
+ it('should return string with a length within a given range', () => {
+ const actual = faker.string.nanoid({ min: 13, max: 37 });
+
+ expect(actual.length).toBeGreaterThanOrEqual(13);
+ expect(actual.length).toBeLessThanOrEqual(37);
+ });
+ });
+
describe('special', () => {
it('should return a value of type string with default length of 1', () => {
const actual = faker.string.special();