Skip to content

Commit

Permalink
fix: MockResponseCallbackOptions type (#2951)
Browse files Browse the repository at this point in the history
* Fix MockResponseCallbackOptions type

* Add tests
  • Loading branch information
merojosa committed May 6, 2024
1 parent 6866d29 commit de5790a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions test/types/mock-interceptor.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ expectAssignable<BodyInit | Dispatcher.DispatchOptions['body']>(mockResponseCall
trailers: { foo: 'bar' }
}})))
mockInterceptor.reply((options) => {
expectAssignable<MockInterceptor.MockResponseCallbackOptions["path"]>(options.path);
expectAssignable<MockInterceptor.MockResponseCallbackOptions["method"]>(options.method);
expectAssignable<MockInterceptor.MockResponseCallbackOptions['headers']>(options.headers);
expectAssignable<MockInterceptor.MockResponseCallbackOptions['origin']>(options.origin);
expectAssignable<MockInterceptor.MockResponseCallbackOptions['body']>(options.body);
expectAssignable<MockInterceptor.MockResponseCallbackOptions["maxRedirections"]>(options.maxRedirections);
return { statusCode: 200, data: { foo: 'bar' } }
})

Expand Down
8 changes: 4 additions & 4 deletions types/mock-interceptor.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ declare namespace MockInterceptor {

export interface MockResponseCallbackOptions {
path: string;
origin: string;
method: string;
body?: BodyInit | Dispatcher.DispatchOptions['body'];
headers: Headers | Record<string, string>;
maxRedirections: number;
headers?: Headers | Record<string, string>;
origin?: string;
body?: BodyInit | Dispatcher.DispatchOptions['body'] | null;
maxRedirections?: number;
}

export type MockResponseDataHandler<TData extends object = object> = (
Expand Down

0 comments on commit de5790a

Please sign in to comment.