UNPKG

thrilled-be-testing

Version:

Testing utilities and helpers package with Jest, Supertest, and database testing support for Express applications

51 lines 1.87 kB
import { Response } from 'supertest'; import { Express } from 'express'; export interface SimpleHttpTestOptions { headers?: Record<string, string>; timeout?: number; expect?: { status?: number; body?: any; headers?: Record<string, string>; }; } export declare class SimpleHttpTestClient { private app; private baseHeaders; constructor(app: Express, options?: SimpleHttpTestOptions); get(path: string, options?: SimpleHttpTestOptions): Promise<Response>; post(path: string, body?: any, options?: SimpleHttpTestOptions): Promise<Response>; put(path: string, body?: any, options?: SimpleHttpTestOptions): Promise<Response>; delete(path: string, options?: SimpleHttpTestOptions): Promise<Response>; withAuth(token: string): SimpleHttpTestClient; withHeaders(headers: Record<string, string>): SimpleHttpTestClient; } export declare class SimpleResponseAssertions { private response; constructor(response: Response); static assert(response: Response): SimpleResponseAssertions; hasStatus(status: number): this; hasSuccessStatus(): this; hasErrorStatus(): this; hasContentType(contentType: string): this; hasJsonBody(): this; hasBodyProperty(property: string, value?: any): this; hasBodyMatching(expectedBody: any): this; } export interface SimpleApiTestCase { name: string; method: 'GET' | 'POST' | 'PUT' | 'DELETE'; path: string; body?: any; headers?: Record<string, string>; expectedStatus: number; expectedBody?: any; auth?: string; } export declare class SimpleApiTestRunner { private client; constructor(client: SimpleHttpTestClient); runTestCase(testCase: SimpleApiTestCase): Promise<void>; runTestCases(testCases: SimpleApiTestCase[]): Promise<void>; } //# sourceMappingURL=simple-api-testing.d.ts.map