Skip to content

Commit 5a15c40

Browse files
docs: deprecate randomize (#506)
1 parent 1327b23 commit 5a15c40

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/helpers.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,15 @@ export class Helpers {
137137
* @example
138138
* faker.helpers.randomize() // 'c'
139139
* faker.helpers.randomize([1, 2, 3]) // '2'
140+
*
141+
* @deprecated
140142
*/
141-
// TODO ST-DDT 2022-02-06: Mark as deprecated
142143
randomize<T = string>(
143144
array: ReadonlyArray<T> = ['a', 'b', 'c'] as unknown as ReadonlyArray<T>
144145
): T {
146+
console.warn(
147+
'Deprecation Warning: faker.helpers.randomize is now located in faker.random.arrayElement'
148+
);
145149
return this.faker.random.arrayElement(array);
146150
}
147151

test/helpers.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,22 @@ describe('helpers', () => {
764764
expect(transaction.account).toBeTruthy();
765765
});
766766
});
767+
768+
describe('deprecation warnings', () => {
769+
it.each([['randomize', 'random.arrayElement']])(
770+
'should warn user that function helpers.%s is deprecated',
771+
(functionName, newLocation) => {
772+
const spy = vi.spyOn(console, 'warn');
773+
774+
faker.helpers[functionName]();
775+
776+
expect(spy).toHaveBeenCalledWith(
777+
`Deprecation Warning: faker.helpers.${functionName} is now located in faker.${newLocation}`
778+
);
779+
spy.mockRestore();
780+
}
781+
);
782+
});
767783
}
768784
});
769785
describe('deprecation warnings', () => {

0 commit comments

Comments
 (0)