Skip to content

Commit 6096cb4

Browse files
authored
chore: deprecate name.title() in favor of name.jobTitle() (#766)
1 parent 214a77b commit 6096cb4

File tree

2 files changed

+34
-20
lines changed

2 files changed

+34
-20
lines changed

src/name.ts

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -284,23 +284,22 @@ export class Name {
284284
}
285285

286286
/**
287-
* Generates a random title.
287+
* Generates a random job title.
288288
*
289289
* @example
290290
* faker.name.title() // 'International Integration Manager'
291+
*
292+
* @deprecated
291293
*/
292294
title(): string {
293-
const descriptor = this.faker.random.arrayElement(
294-
this.faker.definitions.name.title.descriptor
295-
);
296-
const level = this.faker.random.arrayElement(
297-
this.faker.definitions.name.title.level
298-
);
299-
const job = this.faker.random.arrayElement(
300-
this.faker.definitions.name.title.job
301-
);
302-
303-
return descriptor + ' ' + level + ' ' + job;
295+
deprecated({
296+
deprecated: 'faker.name.title()',
297+
proposed: 'faker.name.jobTitle()',
298+
since: 'v6.1.2',
299+
until: 'v7.0.0',
300+
});
301+
302+
return this.jobTitle();
304303
}
305304

306305
/**
@@ -310,13 +309,7 @@ export class Name {
310309
* faker.name.jobTitle() // 'Global Accounts Engineer'
311310
*/
312311
jobTitle(): string {
313-
return (
314-
this.faker.name.jobDescriptor() +
315-
' ' +
316-
this.faker.name.jobArea() +
317-
' ' +
318-
this.faker.name.jobType()
319-
);
312+
return this.jobDescriptor() + ' ' + this.jobArea() + ' ' + this.jobType();
320313
}
321314

322315
/**

test/name.spec.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,14 +519,35 @@ describe('name', () => {
519519
faker.localeFallback = 'en';
520520
});
521521

522+
it('should display deprecated message', () => {
523+
const spy = vi.spyOn(console, 'warn');
524+
525+
faker.name.title();
526+
527+
expect(spy).toHaveBeenCalledWith(
528+
'[@faker-js/faker]: faker.name.title() is deprecated since v6.1.2 and will be removed in v7.0.0. Please use faker.name.jobTitle() instead.'
529+
);
530+
531+
spy.mockRestore();
532+
});
533+
534+
it('should call jobTitle()', () => {
535+
const spy = vi.spyOn(faker.name, 'jobTitle');
536+
537+
faker.name.title();
538+
539+
expect(spy).toHaveBeenCalledWith();
540+
541+
spy.mockRestore();
542+
});
543+
522544
it('should return a title consisting of a descriptor, area, and type', () => {
523545
const title = faker.name.title();
524546

525547
expect(title).toBeTypeOf('string');
526548

527549
const [descriptor, level, job] = title.split(' ');
528550

529-
// TODO @Shinigami92 2022-01-31: jobTitle and title are the same
530551
expect(faker.definitions.name.title.descriptor).toContain(descriptor);
531552
expect(faker.definitions.name.title.level).toContain(level);
532553
expect(faker.definitions.name.title.job).toContain(job);

0 commit comments

Comments
 (0)