Packages@robojs/server
testHandler()
Function: testHandler()
function testHandler<T>(handler, options): Promise<T>Tests a specific handler function directly without method dispatch. Use this when you want to test a single handler in isolation.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
handler | (request) => T | Promise<T> |
options | TestRequestOptions |
Returns
Promise<T>
Example
import { testHandler } from '@robojs/server/testing'
import { GET } from '../src/api/users/[id]'
const result = await testHandler(GET, {
params: { id: '123' }
})
// Result is the raw return value from the handler
expect(result).toEqual({ id: '123', name: 'John' })