diff options
| author | Leyla Jähnig <[email protected]> | 2022-04-30 10:56:32 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-04-30 10:56:32 +0200 |
| commit | 36cd4612a98c34edad4397ac5f69652b17fe2bf3 (patch) | |
| tree | 7ba499aa37c7f24cc1ca6bda3391ee9622af5e8c /test | |
| parent | 6cfd1e1287289ac8199b4e93ba2e0f42c0e262f1 (diff) | |
| download | faker-36cd4612a98c34edad4397ac5f69652b17fe2bf3.tar.xz faker-36cd4612a98c34edad4397ac5f69652b17fe2bf3.zip | |
feat: separate methods for object key value (#503)
Co-authored-by: Leyla Jähnig <[email protected]>
Co-authored-by: Shinigami92 <[email protected]>
Diffstat (limited to 'test')
| -rw-r--r-- | test/helpers.spec.ts | 26 | ||||
| -rw-r--r-- | test/random.spec.ts | 14 |
2 files changed, 40 insertions, 0 deletions
diff --git a/test/helpers.spec.ts b/test/helpers.spec.ts index 5ee4b2a7..3f63a807 100644 --- a/test/helpers.spec.ts +++ b/test/helpers.spec.ts @@ -831,6 +831,32 @@ describe('helpers', () => { }); }); + describe('objectKey', () => { + it('should return a random key', () => { + const testObject = { + hello: 'to', + you: 'my', + friend: '!', + }; + const actual = faker.helpers.objectKey(testObject); + + expect(Object.keys(testObject)).toContain(actual); + }); + }); + + describe('objectValue', () => { + it('should return a random value', () => { + const testObject = { + hello: 'to', + you: 'my', + friend: '!', + }; + const actual = faker.helpers.objectValue(testObject); + + expect(Object.values(testObject)).toContain(actual); + }); + }); + describe('deprecation warnings', () => { it.each([['randomize', 'random.arrayElement']])( 'should warn user that function helpers.%s is deprecated', diff --git a/test/random.spec.ts b/test/random.spec.ts index f3a47d87..a3c93562 100644 --- a/test/random.spec.ts +++ b/test/random.spec.ts @@ -159,6 +159,8 @@ describe('random', () => { describe('objectElement', () => { it('should return a random value', () => { + const spy = vi.spyOn(console, 'warn'); + const testObject = { hello: 'to', you: 'my', @@ -167,9 +169,16 @@ describe('random', () => { const actual = faker.random.objectElement(testObject); expect(Object.values(testObject)).toContain(actual); + expect(spy).toHaveBeenCalledWith( + `[@faker-js/faker]: faker.random.objectElement() is deprecated since v6.3.0 and will be removed in v7.0.0. Please use faker.helpers.objectValue() instead.` + ); + + spy.mockRestore(); }); it('should return a random key', () => { + const spy = vi.spyOn(console, 'warn'); + const testObject = { hello: 'to', you: 'my', @@ -178,6 +187,11 @@ describe('random', () => { const actual = faker.random.objectElement(testObject, 'key'); expect(Object.keys(testObject)).toContain(actual); + expect(spy).toHaveBeenCalledWith( + `[@faker-js/faker]: faker.random.objectElement(obj, 'key') is deprecated since v6.3.0 and will be removed in v7.0.0. Please use faker.helpers.objectKey() instead.` + ); + + spy.mockRestore(); }); }); |
