Skip to content

Commit

Permalink
chore: spread handlers on "validateHandlers"
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito committed Nov 15, 2022
1 parent a06a944 commit 002016d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/SetupApi.ts
Expand Up @@ -23,7 +23,7 @@ export abstract class SetupApi<EventsMap extends EventMapType> {
public readonly events: LifeCycleEventEmitter<EventsMap>

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

this.initialHandlers = toReadonlyArray(initialHandlers)
this.currentHandlers = [...initialHandlers]
Expand All @@ -35,7 +35,7 @@ export abstract class SetupApi<EventsMap extends EventMapType> {
this.events = this.createLifeCycleEvents()
}

private validateHandlers(handlers: ReadonlyArray<RequestHandler>): void {
private validateHandlers(...handlers: ReadonlyArray<RequestHandler>): void {
// Guard against incorrect call signature of the setup API.
for (const handler of handlers) {
invariant(
Expand Down
18 changes: 11 additions & 7 deletions 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({
Expand All @@ -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.',
),
]),
)
})
})

0 comments on commit 002016d

Please sign in to comment.