Skip to content

Commit

Permalink
fix(SetupApi): validate given request handlers (#1460)
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito committed Nov 15, 2022
1 parent 99d49f9 commit a06a944
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/SetupApi.ts
Expand Up @@ -22,7 +22,7 @@ export abstract class SetupApi<EventsMap extends EventMapType> {

public readonly events: LifeCycleEventEmitter<EventsMap>

constructor(initialHandlers: Array<RequestHandler>) {
constructor(...initialHandlers: Array<RequestHandler>) {
this.validateHandlers(initialHandlers)

this.initialHandlers = toReadonlyArray(initialHandlers)
Expand Down
2 changes: 1 addition & 1 deletion src/native/index.ts
Expand Up @@ -12,5 +12,5 @@ export function setupServer(
): SetupServerApi {
// Provision request interception via patching the `XMLHttpRequest` class only
// in React Native. There is no `http`/`https` modules in that environment.
return new SetupServerApi([XMLHttpRequestInterceptor], handlers)
return new SetupServerApi([XMLHttpRequestInterceptor], ...handlers)
}
4 changes: 2 additions & 2 deletions src/node/SetupServerApi.ts
Expand Up @@ -39,9 +39,9 @@ export class SetupServerApi extends SetupApi<ServerLifecycleEventsMap> {
interceptors: Array<{
new (): Interceptor<HttpRequestEventMap>
}>,
handlers: Array<RequestHandler>,
...handlers: Array<RequestHandler>
) {
super(handlers)
super(...handlers)

this.interceptor = new BatchInterceptor({
name: 'setup-server',
Expand Down
2 changes: 1 addition & 1 deletion src/node/setupServer.ts
Expand Up @@ -13,6 +13,6 @@ export const setupServer = (
): SetupServerApi => {
return new SetupServerApi(
[ClientRequestInterceptor, XMLHttpRequestInterceptor],
handlers,
...handlers,
)
}
6 changes: 3 additions & 3 deletions src/setupWorker/setupWorker.ts
Expand Up @@ -32,8 +32,8 @@ export class SetupWorkerApi extends SetupApi<WorkerLifecycleEventsMap> {
private stopHandler: StopHandler = null as any
private listeners: Array<Listener>

constructor(handlers: Array<RequestHandler>) {
super(handlers)
constructor(...handlers: Array<RequestHandler>) {
super(...handlers)

invariant(
!isNodeProcess(),
Expand Down Expand Up @@ -224,5 +224,5 @@ export class SetupWorkerApi extends SetupApi<WorkerLifecycleEventsMap> {
export function setupWorker(
...handlers: Array<RequestHandler>
): SetupWorkerApi {
return new SetupWorkerApi(handlers)
return new SetupWorkerApi(...handlers)
}

0 comments on commit a06a944

Please sign in to comment.