aboutsummaryrefslogtreecommitdiff
path: root/test/modules
diff options
context:
space:
mode:
authorSuyash Gulati <[email protected]>2024-10-13 04:23:36 +0530
committerGitHub <[email protected]>2024-10-12 22:53:36 +0000
commit34cf3643bee275f23bc7a39376c1b3d542a8c45f (patch)
tree712ee3ca0530f2291b9a95cb3d690207ea128db1 /test/modules
parente271d4a545dd48e57285019e4f412358c49cad0d (diff)
downloadfaker-34cf3643bee275f23bc7a39376c1b3d542a8c45f.tar.xz
faker-34cf3643bee275f23bc7a39376c1b3d542a8c45f.zip
refactor(internet): rename userName method to username (#3130)
Diffstat (limited to 'test/modules')
-rw-r--r--test/modules/__snapshots__/internet.spec.ts.snap48
-rw-r--r--test/modules/internet.spec.ts100
2 files changed, 141 insertions, 7 deletions
diff --git a/test/modules/__snapshots__/internet.spec.ts.snap b/test/modules/__snapshots__/internet.spec.ts.snap
index 9ec2d265..a70d9afe 100644
--- a/test/modules/__snapshots__/internet.spec.ts.snap
+++ b/test/modules/__snapshots__/internet.spec.ts.snap
@@ -120,6 +120,22 @@ exports[`internet > 42 > userName > with firstName option 1`] = `"Jane_Wiegand59
exports[`internet > 42 > userName > with lastName option 1`] = `"Garnet_Doe"`;
+exports[`internet > 42 > username > noArgs 1`] = `"Garnet.Reynolds-Miller15"`;
+
+exports[`internet > 42 > username > with Chinese names 1`] = `"hlzp8d.tpv"`;
+
+exports[`internet > 42 > username > with Cyrillic names 1`] = `"Fedor.Dostoevskii"`;
+
+exports[`internet > 42 > username > with Latin names 1`] = `"Jane.Doe"`;
+
+exports[`internet > 42 > username > with accented names 1`] = `"Helene.Muller"`;
+
+exports[`internet > 42 > username > with all option 1`] = `"Jane.Doe"`;
+
+exports[`internet > 42 > username > with firstName option 1`] = `"Jane_Wiegand59"`;
+
+exports[`internet > 42 > username > with lastName option 1`] = `"Garnet_Doe"`;
+
exports[`internet > 1211 > color > noArgs 1`] = `"#77721c"`;
exports[`internet > 1211 > color > with all options 1`] = `"#a9a44e"`;
@@ -240,6 +256,22 @@ exports[`internet > 1211 > userName > with firstName option 1`] = `"Jane99"`;
exports[`internet > 1211 > userName > with lastName option 1`] = `"Tito_Doe"`;
+exports[`internet > 1211 > username > noArgs 1`] = `"Tito67"`;
+
+exports[`internet > 1211 > username > with Chinese names 1`] = `"hlzp8d_tpv89"`;
+
+exports[`internet > 1211 > username > with Cyrillic names 1`] = `"Fedor_Dostoevskii89"`;
+
+exports[`internet > 1211 > username > with Latin names 1`] = `"Jane_Doe89"`;
+
+exports[`internet > 1211 > username > with accented names 1`] = `"Helene_Muller89"`;
+
+exports[`internet > 1211 > username > with all option 1`] = `"Jane_Doe89"`;
+
+exports[`internet > 1211 > username > with firstName option 1`] = `"Jane99"`;
+
+exports[`internet > 1211 > username > with lastName option 1`] = `"Tito_Doe"`;
+
exports[`internet > 1337 > color > noArgs 1`] = `"#211423"`;
exports[`internet > 1337 > color > with all options 1`] = `"#534655"`;
@@ -359,3 +391,19 @@ exports[`internet > 1337 > userName > with all option 1`] = `"Jane.Doe15"`;
exports[`internet > 1337 > userName > with firstName option 1`] = `"Jane.Cronin45"`;
exports[`internet > 1337 > userName > with lastName option 1`] = `"Devyn.Doe27"`;
+
+exports[`internet > 1337 > username > noArgs 1`] = `"Devyn.Gottlieb"`;
+
+exports[`internet > 1337 > username > with Chinese names 1`] = `"hlzp8d.tpv15"`;
+
+exports[`internet > 1337 > username > with Cyrillic names 1`] = `"Fedor.Dostoevskii15"`;
+
+exports[`internet > 1337 > username > with Latin names 1`] = `"Jane.Doe15"`;
+
+exports[`internet > 1337 > username > with accented names 1`] = `"Helene.Muller15"`;
+
+exports[`internet > 1337 > username > with all option 1`] = `"Jane.Doe15"`;
+
+exports[`internet > 1337 > username > with firstName option 1`] = `"Jane.Cronin45"`;
+
+exports[`internet > 1337 > username > with lastName option 1`] = `"Devyn.Doe27"`;
diff --git a/test/modules/internet.spec.ts b/test/modules/internet.spec.ts
index 04b255fd..f96671eb 100644
--- a/test/modules/internet.spec.ts
+++ b/test/modules/internet.spec.ts
@@ -66,6 +66,20 @@ describe('internet', () => {
.it('with Chinese names', { firstName: '大羽', lastName: '陳' });
});
+ t.describe('username', (t) => {
+ t.it('noArgs')
+ .it('with firstName option', { firstName: 'Jane' })
+ .it('with lastName option', { lastName: 'Doe' })
+ .it('with all option', { firstName: 'Jane', lastName: 'Doe' })
+ .it('with Latin names', { firstName: 'Jane', lastName: 'Doe' })
+ .it('with accented names', { firstName: 'Hélene', lastName: 'Müller' })
+ .it('with Cyrillic names', {
+ firstName: 'Фёдор',
+ lastName: 'Достоевский',
+ })
+ .it('with Chinese names', { firstName: '大羽', lastName: '陳' });
+ });
+
t.describe('displayName', (t) => {
t.it('noArgs')
.it('with firstName option', { firstName: 'Jane' })
@@ -347,8 +361,80 @@ describe('internet', () => {
});
describe('userName()', () => {
+ it('should return a random userName', () => {
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
+ const userName = faker.internet.userName();
+
+ expect(userName).toBeTruthy();
+ expect(userName).toBeTypeOf('string');
+ expect(userName).toMatch(/\w/);
+ });
+
+ it('should return a random userName with given firstName', () => {
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
+ const userName = faker.internet.userName({ firstName: 'Aiden' });
+
+ expect(userName).toBeTruthy();
+ expect(userName).toBeTypeOf('string');
+ expect(userName).toMatch(/\w/);
+ expect(userName).includes('Aiden');
+ });
+
+ it('should return a random userName with given firstName and lastName', () => {
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
+ const userName = faker.internet.userName({
+ firstName: 'Aiden',
+ lastName: 'Harann',
+ });
+
+ expect(userName).toBeTruthy();
+ expect(userName).toBeTypeOf('string');
+ expect(userName).includes('Aiden');
+ expect(userName).includes('Harann');
+ expect(userName).toMatch(/^Aiden[._]Harann\d*/);
+ });
+
+ it('should strip accents', () => {
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
+ const userName = faker.internet.userName({
+ firstName: 'Adèle',
+ lastName: 'Smith',
+ });
+ expect(userName).includes('Adele');
+ expect(userName).includes('Smith');
+ });
+
+ it('should transliterate Cyrillic', () => {
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
+ const userName = faker.internet.userName({
+ firstName: 'Амос',
+ lastName: 'Васильев',
+ });
+ expect(userName).includes('Amos');
+ });
+
+ it('should provide a fallback for Chinese etc', () => {
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
+ const userName = faker.internet.userName({
+ firstName: '大羽',
+ lastName: '陳',
+ });
+ expect(userName).includes('hlzp8d');
+ });
+
+ it('should provide a fallback special unicode characters', () => {
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
+ const userName = faker.internet.userName({
+ firstName: '🐼',
+ lastName: '❤️',
+ });
+ expect(userName).includes('2qt8');
+ });
+ });
+
+ describe('username()', () => {
it('should return a random username', () => {
- const username = faker.internet.userName();
+ const username = faker.internet.username();
expect(username).toBeTruthy();
expect(username).toBeTypeOf('string');
@@ -356,7 +442,7 @@ describe('internet', () => {
});
it('should return a random username with given firstName', () => {
- const username = faker.internet.userName({ firstName: 'Aiden' });
+ const username = faker.internet.username({ firstName: 'Aiden' });
expect(username).toBeTruthy();
expect(username).toBeTypeOf('string');
@@ -365,7 +451,7 @@ describe('internet', () => {
});
it('should return a random username with given firstName and lastName', () => {
- const username = faker.internet.userName({
+ const username = faker.internet.username({
firstName: 'Aiden',
lastName: 'Harann',
});
@@ -378,7 +464,7 @@ describe('internet', () => {
});
it('should strip accents', () => {
- const username = faker.internet.userName({
+ const username = faker.internet.username({
firstName: 'Adèle',
lastName: 'Smith',
});
@@ -387,7 +473,7 @@ describe('internet', () => {
});
it('should transliterate Cyrillic', () => {
- const username = faker.internet.userName({
+ const username = faker.internet.username({
firstName: 'Амос',
lastName: 'Васильев',
});
@@ -395,7 +481,7 @@ describe('internet', () => {
});
it('should provide a fallback for Chinese etc', () => {
- const username = faker.internet.userName({
+ const username = faker.internet.username({
firstName: '大羽',
lastName: '陳',
});
@@ -403,7 +489,7 @@ describe('internet', () => {
});
it('should provide a fallback special unicode characters', () => {
- const username = faker.internet.userName({
+ const username = faker.internet.username({
firstName: '🐼',
lastName: '❤️',
});