diff options
| author | Shinigami <[email protected]> | 2022-05-01 15:28:11 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-05-01 13:28:11 +0000 |
| commit | e9c2b9de8dfa041401d16cddf976d235cf2dd495 (patch) | |
| tree | 98fd503dbe9965d9da914d463f1bbbd3d54b5a9f | |
| parent | c093e4c300a5566faafc85289d2588742db25c5d (diff) | |
| download | faker-e9c2b9de8dfa041401d16cddf976d235cf2dd495.tar.xz faker-e9c2b9de8dfa041401d16cddf976d235cf2dd495.zip | |
test: add tests (#894)
| -rw-r--r-- | src/helpers.ts | 4 | ||||
| -rw-r--r-- | test/helpers.spec.ts | 10 |
2 files changed, 12 insertions, 2 deletions
diff --git a/src/helpers.ts b/src/helpers.ts index 29b62a51..0d8ce5b0 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -716,7 +716,7 @@ export class Helpers { } /** - * Returns a random key from given object. + * Returns a random key from given object or `undefined` if no key could be found. * * @param object The object to be used. * @@ -729,7 +729,7 @@ export class Helpers { } /** - * Returns a random value from given object. + * Returns a random value from given object or `undefined` if no key could be found. * * @param object The object to be used. * diff --git a/test/helpers.spec.ts b/test/helpers.spec.ts index a34886dd..e436e6dc 100644 --- a/test/helpers.spec.ts +++ b/test/helpers.spec.ts @@ -888,6 +888,11 @@ describe('helpers', () => { expect(Object.keys(testObject)).toContain(actual); }); + + it('should return undefined if given object is empty', () => { + const actual = faker.helpers.objectKey({}); + expect(actual).toBeUndefined(); + }); }); describe('objectValue', () => { @@ -901,6 +906,11 @@ describe('helpers', () => { expect(Object.values(testObject)).toContain(actual); }); + + it('should return undefined if given object is empty', () => { + const actual = faker.helpers.objectValue({}); + expect(actual).toBeUndefined(); + }); }); describe('deprecation warnings', () => { |
