aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/helpers.ts4
-rw-r--r--test/helpers.spec.ts10
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', () => {