codeflash-internal/django/aiservice/testgen/prompts/javascript/execute_async_user_prompt.md
2026-01-14 22:15:27 -08:00

1.5 KiB

Using the {test_framework} testing framework, write a test suite for the following ASYNC JavaScript function.

CRITICAL: This function is ASYNCHRONOUS

  • All test functions MUST be async: test('...', async () => {{ ... }})
  • All calls to {function_name} MUST be awaited: await {function_name}(...)
  • Test both successful and error cases for async operations

Function to Test:

{function_code}

Template to Follow:

// imports
const {{ {function_name} }} = require('{module_path}');

// unit tests
describe('{function_name}', () => {{
    // Basic Test Cases
    describe('Basic async functionality', () => {{
        test('should resolve with correct value', async () => {{
            const result = await {function_name}(/* args */);
            expect(result).toBe(/* expected */);
        }});
    }});

    // Edge Test Cases
    describe('Async edge cases', () => {{
        test('should handle async error case', async () => {{
            await expect({function_name}(/* invalid args */)).rejects.toThrow();
        }});
    }});

    // Large Scale Test Cases
    describe('Concurrent execution tests', () => {{
        test('should handle multiple concurrent calls', async () => {{
            const results = await Promise.all([
                {function_name}(/* args1 */),
                {function_name}(/* args2 */),
            ]);
            // assertions
        }});
    }});
}});

{package_comment}

Reply only with code, in a single markdown code block.