This commit is contained in:
Gregory Schier
2026-03-02 07:52:08 -08:00
parent fbf0473b20
commit 0b250ff5b5
4 changed files with 20 additions and 8 deletions
+8 -4
View File
@@ -13,12 +13,16 @@ describe('template-function-faker', () => {
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');
const onRender = fn?.onRender;
expect(fn?.onRender).toBeTypeOf('function');
expect(onRender).toBeTypeOf('function');
if (onRender == null) {
throw new Error("Expected template function 'faker.date.future' to define onRender");
}
const result = await fn!.onRender!(
{} as Parameters<NonNullable<typeof fn.onRender>>[0],
{ values: {} } as Parameters<NonNullable<typeof fn.onRender>>[1],
const result = await onRender(
{} as Parameters<typeof onRender>[0],
{ values: {} } as Parameters<typeof onRender>[1],
);
expect(result).toMatch(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/);
+4 -1
View File
@@ -206,7 +206,10 @@ export const plugin: PluginDefinition = {
// Create snippet generator
const snippet = new HTTPSnippet(harRequest);
const generateSnippet = (target: string, client: string): string => {
const result = snippet.convert(target as any, client);
const result = snippet.convert(
target as Parameters<typeof snippet.convert>[0],
client as Parameters<typeof snippet.convert>[1],
);
return (Array.isArray(result) ? result.join('\n') : result || '').replace(/\r\n/g, '\n');
};