aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSuyash Gulati <[email protected]>2023-05-03 22:19:50 +0530
committerGitHub <[email protected]>2023-05-03 18:49:50 +0200
commitc092aa1276a5c249de1ada47e807f12dd6de36f7 (patch)
tree0740df1ad8ca2d3d7666e6b78e7ad1af8fae04ed /test
parentede6ffac383a853c12b7a47cebbb031ba80627aa (diff)
downloadfaker-c092aa1276a5c249de1ada47e807f12dd6de36f7.tar.xz
faker-c092aa1276a5c249de1ada47e807f12dd6de36f7.zip
feat(helpers): new method `objectEntry` (#2123)
Diffstat (limited to 'test')
-rw-r--r--test/__snapshots__/helpers.spec.ts.snap21
-rw-r--r--test/helpers.spec.ts25
2 files changed, 46 insertions, 0 deletions
diff --git a/test/__snapshots__/helpers.spec.ts.snap b/test/__snapshots__/helpers.spec.ts.snap
index 64562da7..04af3ac0 100644
--- a/test/__snapshots__/helpers.spec.ts.snap
+++ b/test/__snapshots__/helpers.spec.ts.snap
@@ -110,6 +110,13 @@ exports[`helpers > 42 > mustache > template with method 1`] = `"Hello John!"`;
exports[`helpers > 42 > mustache > template with string 1`] = `"Hello John!"`;
+exports[`helpers > 42 > objectEntry > simple 1`] = `
+[
+ "b",
+ 2,
+]
+`;
+
exports[`helpers > 42 > objectKey > simple 1`] = `"b"`;
exports[`helpers > 42 > objectValue > simple 1`] = `2`;
@@ -343,6 +350,13 @@ exports[`helpers > 1211 > mustache > template with method 1`] = `"Hello John!"`;
exports[`helpers > 1211 > mustache > template with string 1`] = `"Hello John!"`;
+exports[`helpers > 1211 > objectEntry > simple 1`] = `
+[
+ "c",
+ 3,
+]
+`;
+
exports[`helpers > 1211 > objectKey > simple 1`] = `"c"`;
exports[`helpers > 1211 > objectValue > simple 1`] = `3`;
@@ -558,6 +572,13 @@ exports[`helpers > 1337 > mustache > template with method 1`] = `"Hello John!"`;
exports[`helpers > 1337 > mustache > template with string 1`] = `"Hello John!"`;
+exports[`helpers > 1337 > objectEntry > simple 1`] = `
+[
+ "a",
+ 1,
+]
+`;
+
exports[`helpers > 1337 > objectKey > simple 1`] = `"a"`;
exports[`helpers > 1337 > objectValue > simple 1`] = `1`;
diff --git a/test/helpers.spec.ts b/test/helpers.spec.ts
index 6cb397cb..437a3284 100644
--- a/test/helpers.spec.ts
+++ b/test/helpers.spec.ts
@@ -157,6 +157,10 @@ describe('helpers', () => {
t.it('simple', { a: 1, b: 2, c: 3 });
});
+ t.describe('objectEntry', (t) => {
+ t.it('simple', { a: 1, b: 2, c: 3 });
+ });
+
t.describe('fake', (t) => {
t.it('with empty string', '')
.it('with a static template', 'my test string')
@@ -935,6 +939,27 @@ describe('helpers', () => {
});
});
+ describe('objectEntry', () => {
+ it('should return a random key, value pair', () => {
+ const testObject = {
+ hello: 'to',
+ you: 'my',
+ friend: '!',
+ };
+ const [key, value] = faker.helpers.objectEntry(testObject);
+
+ expect(Object.keys(testObject)).toContain(key);
+ expect(Object.values(testObject)).toContain(value);
+ expect(testObject[key]).toEqual(value);
+ });
+
+ it('should throw if given object is empty', () => {
+ expect(() => faker.helpers.objectEntry({})).toThrowError(
+ new FakerError('Cannot get value from empty dataset.')
+ );
+ });
+ });
+
describe('fake()', () => {
it('does allow empty string input', () => {
const actual = faker.helpers.fake('');