aboutsummaryrefslogtreecommitdiff
path: root/test/string.spec.ts
diff options
context:
space:
mode:
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();