|
1 | 1 | import { afterEach, beforeEach, describe, expect, it } from 'vitest'; |
2 | 2 | import { faker } from '../src'; |
| 3 | +import type { Name } from '../src/modules/name'; |
3 | 4 | import { seededRuns } from './support/seededRuns'; |
4 | 5 |
|
5 | 6 | const NON_SEEDED_BASED_RUN = 5; |
6 | 7 |
|
7 | | -const functionNames = [ |
| 8 | +const functionNames: (keyof Name)[] = [ |
| 9 | + 'findName', |
8 | 10 | 'firstName', |
| 11 | + 'fullName', |
| 12 | + 'gender', |
| 13 | + 'jobArea', |
| 14 | + 'jobDescriptor', |
| 15 | + 'jobTitle', |
| 16 | + 'jobType', |
9 | 17 | 'lastName', |
10 | 18 | 'middleName', |
11 | | - 'findName', |
12 | | - 'jobTitle', |
13 | | - 'gender', |
14 | 19 | 'prefix', |
15 | 20 | 'suffix', |
16 | | - 'jobDescriptor', |
17 | | - 'jobArea', |
18 | | - 'jobType', |
19 | 21 | ]; |
20 | 22 |
|
21 | 23 | describe('name', () => { |
@@ -226,6 +228,100 @@ describe('name', () => { |
226 | 228 | }); |
227 | 229 | }); |
228 | 230 |
|
| 231 | + describe('fullName()', () => { |
| 232 | + beforeEach(() => { |
| 233 | + faker.locale = 'en'; |
| 234 | + faker.localeFallback = 'en'; |
| 235 | + }); |
| 236 | + |
| 237 | + it('should return a name with firstName and lastName', () => { |
| 238 | + const fullName = faker.name.fullName(); |
| 239 | + |
| 240 | + expect(fullName).toBeTypeOf('string'); |
| 241 | + expect(fullName).toContain(' '); |
| 242 | + }); |
| 243 | + |
| 244 | + it('should return a female gender-specific name without firstName and lastName', () => { |
| 245 | + faker.locale = 'mk'; |
| 246 | + |
| 247 | + const female_specific = [ |
| 248 | + ...faker.definitions.name.female_prefix, |
| 249 | + ...faker.definitions.name.female_first_name, |
| 250 | + ...faker.definitions.name.female_last_name, |
| 251 | + ...faker.definitions.name.suffix, |
| 252 | + ]; |
| 253 | + |
| 254 | + const fullName = faker.name.fullName({ gender: 'female' }); |
| 255 | + |
| 256 | + const parts = fullName.split(' '); |
| 257 | + for (const part of parts) { |
| 258 | + expect(female_specific).toContain(part); |
| 259 | + } |
| 260 | + }); |
| 261 | + |
| 262 | + it('should return a male gender-specific name without firstName and lastName', () => { |
| 263 | + faker.locale = 'mk'; |
| 264 | + |
| 265 | + const male_specific = [ |
| 266 | + ...faker.definitions.name.male_prefix, |
| 267 | + ...faker.definitions.name.male_first_name, |
| 268 | + ...faker.definitions.name.male_last_name, |
| 269 | + ...faker.definitions.name.suffix, |
| 270 | + ]; |
| 271 | + |
| 272 | + const fullName = faker.name.fullName({ gender: 'male' }); |
| 273 | + |
| 274 | + const parts = fullName.split(' '); |
| 275 | + for (const part of parts) { |
| 276 | + expect(male_specific).toContain(part); |
| 277 | + } |
| 278 | + }); |
| 279 | + |
| 280 | + it('should return a female gender-specific name with given firstName and lastName', () => { |
| 281 | + faker.locale = 'mk'; |
| 282 | + |
| 283 | + const male_specific = [ |
| 284 | + ...faker.definitions.name.female_prefix, |
| 285 | + 'firstName', |
| 286 | + 'lastName', |
| 287 | + ...faker.definitions.name.suffix, |
| 288 | + ]; |
| 289 | + |
| 290 | + const fullName = faker.name.fullName({ |
| 291 | + firstName: 'firstName', |
| 292 | + lastName: 'lastName', |
| 293 | + gender: 'female', |
| 294 | + }); |
| 295 | + |
| 296 | + const parts = fullName.split(' '); |
| 297 | + for (const part of parts) { |
| 298 | + expect(male_specific).toContain(part); |
| 299 | + } |
| 300 | + }); |
| 301 | + |
| 302 | + it('should return a male gender-specific name with given firstName and lastName', () => { |
| 303 | + faker.locale = 'mk'; |
| 304 | + |
| 305 | + const male_specific = [ |
| 306 | + ...faker.definitions.name.male_prefix, |
| 307 | + 'firstName', |
| 308 | + 'lastName', |
| 309 | + ...faker.definitions.name.suffix, |
| 310 | + ]; |
| 311 | + |
| 312 | + const fullName = faker.name.fullName({ |
| 313 | + firstName: 'firstName', |
| 314 | + lastName: 'lastName', |
| 315 | + gender: 'male', |
| 316 | + }); |
| 317 | + |
| 318 | + const parts = fullName.split(' '); |
| 319 | + for (const part of parts) { |
| 320 | + expect(male_specific).toContain(part); |
| 321 | + } |
| 322 | + }); |
| 323 | + }); |
| 324 | + |
229 | 325 | describe('gender()', () => { |
230 | 326 | beforeEach(() => { |
231 | 327 | faker.locale = 'en'; |
|
0 commit comments