Skip to content

Commit

Permalink
docs: deprecate randomize (#506)
Browse files Browse the repository at this point in the history
  • Loading branch information
xDivisionByZerox committed Mar 21, 2022
1 parent 1327b23 commit 5a15c40
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,15 @@ export class Helpers {
* @example
* faker.helpers.randomize() // 'c'
* faker.helpers.randomize([1, 2, 3]) // '2'
*
* @deprecated
*/
// TODO ST-DDT 2022-02-06: Mark as deprecated
randomize<T = string>(
array: ReadonlyArray<T> = ['a', 'b', 'c'] as unknown as ReadonlyArray<T>
): T {
console.warn(
'Deprecation Warning: faker.helpers.randomize is now located in faker.random.arrayElement'
);
return this.faker.random.arrayElement(array);
}

Expand Down
16 changes: 16 additions & 0 deletions test/helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,22 @@ describe('helpers', () => {
expect(transaction.account).toBeTruthy();
});
});

describe('deprecation warnings', () => {
it.each([['randomize', 'random.arrayElement']])(
'should warn user that function helpers.%s is deprecated',
(functionName, newLocation) => {
const spy = vi.spyOn(console, 'warn');

faker.helpers[functionName]();

expect(spy).toHaveBeenCalledWith(
`Deprecation Warning: faker.helpers.${functionName} is now located in faker.${newLocation}`
);
spy.mockRestore();
}
);
});
}
});
describe('deprecation warnings', () => {
Expand Down

0 comments on commit 5a15c40

Please sign in to comment.