Skip to content

Commit 5458620

Browse files
authored
fix(helpers): lazy results in fake (#3852)
1 parent 70994db commit 5458620

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/modules/helpers/eval.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ function resolveProperty(entrypoint: unknown, key: string): unknown {
217217
return undefined;
218218
}
219219

220-
return entrypoint?.[key as keyof typeof entrypoint];
220+
return resolveProperty(entrypoint, key);
221221
}
222222

223223
case 'object': {

test/modules/helpers-eval.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,17 @@ describe('fakeEval()', () => {
9999
expect(faker.definitions.airline.airline).toContain(actual);
100100
});
101101

102+
it('supports returning lazy results', () => {
103+
faker.rawDefinitions.custom = {
104+
lazy: () => ({
105+
key: 'lazy result',
106+
}),
107+
};
108+
const actual = fakeEval('custom.lazy.key', faker);
109+
expect(actual).toBeTypeOf('string');
110+
expect(actual).toBe('lazy result');
111+
});
112+
102113
it('supports patterns after a function call', () => {
103114
const actual = fakeEval('airline.airline().name', faker);
104115
expect(actual).toBeTypeOf('string');

0 commit comments

Comments
 (0)