From 002016d44632248fd585ec49a5005fc5f7183a2b Mon Sep 17 00:00:00 2001 From: Artem Zakharchenko Date: Tue, 15 Nov 2022 15:25:38 +0100 Subject: [PATCH] chore: spread handlers on "validateHandlers" --- src/SetupApi.ts | 4 ++-- .../setup-worker/input-validation.test.ts | 18 +++++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/SetupApi.ts b/src/SetupApi.ts index 9b8a47112..9895fe91a 100644 --- a/src/SetupApi.ts +++ b/src/SetupApi.ts @@ -23,7 +23,7 @@ export abstract class SetupApi { public readonly events: LifeCycleEventEmitter constructor(...initialHandlers: Array) { - this.validateHandlers(initialHandlers) + this.validateHandlers(...initialHandlers) this.initialHandlers = toReadonlyArray(initialHandlers) this.currentHandlers = [...initialHandlers] @@ -35,7 +35,7 @@ export abstract class SetupApi { this.events = this.createLifeCycleEvents() } - private validateHandlers(handlers: ReadonlyArray): void { + private validateHandlers(...handlers: ReadonlyArray): void { // Guard against incorrect call signature of the setup API. for (const handler of handlers) { invariant( diff --git a/test/msw-api/setup-worker/input-validation.test.ts b/test/msw-api/setup-worker/input-validation.test.ts index d2a02661b..d8b9c5f07 100644 --- a/test/msw-api/setup-worker/input-validation.test.ts +++ b/test/msw-api/setup-worker/input-validation.test.ts @@ -1,5 +1,6 @@ import * as path from 'path' import { pageWith } from 'page-with' +import { waitFor } from '../../support/waitFor' test('throws an error given an Array of request handlers to "setupWorker"', async () => { const { page } = await pageWith({ @@ -11,13 +12,16 @@ test('throws an error given an Array of request handlers to "setupWorker"', asyn page.on('pageerror', (error) => { exceptions.push(error.message) }) + await page.reload({ waitUntil: 'networkidle' }) - expect(exceptions).toEqual( - expect.arrayContaining([ - expect.stringContaining( - '[MSW] Failed to construct "SetupWorkerApi" given an Array of request handlers. Make sure you spread the request handlers when calling the respective setup function.', - ), - ]), - ) + await waitFor(() => { + expect(exceptions).toEqual( + expect.arrayContaining([ + expect.stringContaining( + '[MSW] Failed to construct "SetupWorkerApi" given an Array of request handlers. Make sure you spread the request handlers when calling the respective setup function.', + ), + ]), + ) + }) })