aboutsummaryrefslogtreecommitdiff
path: root/test/modules/helpers.spec.ts
diff options
context:
space:
mode:
authorST-DDT <[email protected]>2023-12-25 01:51:33 +0100
committerGitHub <[email protected]>2023-12-25 01:51:33 +0100
commit24482a30042eec5b553b30d60985e89fd69a8660 (patch)
treefd4c2b351d03d0f06998e364352f461743f63866 /test/modules/helpers.spec.ts
parentc209030a660422a17f73d6f0b307af14507bd56d (diff)
downloadfaker-24482a30042eec5b553b30d60985e89fd69a8660.tar.xz
faker-24482a30042eec5b553b30d60985e89fd69a8660.zip
feat(helpers): add support for complex intermediate types (#2550)
Diffstat (limited to 'test/modules/helpers.spec.ts')
-rw-r--r--test/modules/helpers.spec.ts37
1 files changed, 19 insertions, 18 deletions
diff --git a/test/modules/helpers.spec.ts b/test/modules/helpers.spec.ts
index 1a1db9c5..1b9ba3ae 100644
--- a/test/modules/helpers.spec.ts
+++ b/test/modules/helpers.spec.ts
@@ -1027,34 +1027,35 @@ describe('helpers', () => {
it('does not allow invalid module name', () => {
expect(() => faker.helpers.fake('{{foo.bar}}')).toThrow(
- new FakerError(`Invalid module method or definition: foo.bar
-- faker.foo.bar is not a function
-- faker.definitions.foo.bar is not an array`)
+ new FakerError(`Cannot resolve expression 'foo.bar'`)
);
});
- it('does not allow missing method name', () => {
- expect(() => faker.helpers.fake('{{location}}')).toThrow(
- new FakerError(`Invalid module method or definition: location
-- faker.location is not a function
-- faker.definitions.location is not an array`)
- );
+ it('does allow missing method name', () => {
+ const actual = faker.helpers.fake('{{location}}');
+ expect(actual).toBe('[object Object]');
});
it('does not allow invalid method name', () => {
expect(() => faker.helpers.fake('{{location.foo}}')).toThrow(
- new FakerError(`Invalid module method or definition: location.foo
-- faker.location.foo is not a function
-- faker.definitions.location.foo is not an array`)
+ new FakerError(`Cannot resolve expression 'location.foo'`)
);
});
- it('does not allow invalid definitions data', () => {
- expect(() => faker.helpers.fake('{{finance.credit_card}}')).toThrow(
- new FakerError(`Invalid module method or definition: finance.credit_card
-- faker.finance.credit_card is not a function
-- faker.definitions.finance.credit_card is not an array`)
- );
+ it('should support complex data', () => {
+ const actual = faker.helpers.fake('{{science.unit}}');
+ expect(actual).toBe('[object Object]');
+ });
+
+ it('should support resolving a value in a complex object', () => {
+ const complex = faker.helpers.fake('{{airline.airline}}');
+ expect(complex).toBe('[object Object]');
+
+ const actual = faker.helpers.fake('{{airline.airline.iataCode}}');
+ expect(actual).toBeTypeOf('string');
+ expect(
+ faker.definitions.airline.airline.map(({ iataCode }) => iataCode)
+ ).toContain(actual);
});
it('should be able to return empty strings', () => {