mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-24 17:58:27 +02:00
faker: render Date outputs as ISO strings
This commit is contained in:
@@ -29,6 +29,7 @@ const modules = [
|
|||||||
|
|
||||||
function normalizeResult(result: unknown): string {
|
function normalizeResult(result: unknown): string {
|
||||||
if (typeof result === 'string') return result;
|
if (typeof result === 'string') return result;
|
||||||
|
if (result instanceof Date) return result.toISOString();
|
||||||
return JSON.stringify(result);
|
return JSON.stringify(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,4 +9,18 @@ describe('template-function-faker', () => {
|
|||||||
// accidental additions, removals, or renames across faker upgrades.
|
// accidental additions, removals, or renames across faker upgrades.
|
||||||
expect(names).toMatchSnapshot();
|
expect(names).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('renders date results as unquoted ISO strings', async () => {
|
||||||
|
const { plugin } = await import('../src/index');
|
||||||
|
const fn = plugin.templateFunctions?.find((fn) => fn.name === 'faker.date.future');
|
||||||
|
|
||||||
|
expect(fn?.onRender).toBeTypeOf('function');
|
||||||
|
|
||||||
|
const result = await fn!.onRender!(
|
||||||
|
{} as Parameters<NonNullable<typeof fn.onRender>>[0],
|
||||||
|
{ values: {} } as Parameters<NonNullable<typeof fn.onRender>>[1],
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(result).toMatch(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user