Skip to content

Commit

Permalink
test: update test
Browse files Browse the repository at this point in the history
  • Loading branch information
aiji42 committed May 2, 2022
1 parent 8ac6aa4 commit 3cde494
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/__tests__/handle-fallback.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ jest.mock('next/server', () => ({
NextResponse: jest.fn()
}))

const dummyRequest = { nextUrl: { pathname: '/' } } as NextRequest
const dummyRequest = {
nextUrl: {
pathname: '/',
clone: () => ({
pathname: '/'
})
}
} as NextRequest
const dummyEvent = {} as NextFetchEvent

describe('handleFallback', () => {
Expand Down Expand Up @@ -38,14 +45,17 @@ describe('handleFallback', () => {
dummyRequest,
dummyEvent
)
expect(NextResponse.redirect).toBeCalledWith('/foo/bar', undefined)
expect(NextResponse.redirect).toBeCalledWith(
{ pathname: '/foo/bar' },
undefined
)

handleFallback(
{ type: 'redirect', destination: '/foo/baz', statusCode: 301 },
dummyRequest,
dummyEvent
)
expect(NextResponse.redirect).toBeCalledWith('/foo/baz', 301)
expect(NextResponse.redirect).toBeCalledWith({ pathname: '/foo/baz' }, 301)
})

test('prevent redirection loop', () => {
Expand All @@ -66,6 +76,6 @@ describe('handleFallback', () => {
dummyRequest,
dummyEvent
)
expect(NextResponse.rewrite).toBeCalledWith('/foo/bar')
expect(NextResponse.rewrite).toBeCalledWith({ pathname: '/foo/bar' })
})
})

0 comments on commit 3cde494

Please sign in to comment.