Skip to content

Commit

Permalink
test: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aiji42 committed Dec 21, 2021
1 parent 6599177 commit 4f77b2b
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 @@ -2,10 +2,7 @@ import { handleFallback } from '../handle-fallback'
import { NextFetchEvent, NextRequest, NextResponse } from 'next/server'

jest.mock('next/server', () => ({
NextResponse: {
rewrite: jest.fn(),
redirect: jest.fn()
}
NextResponse: jest.fn()
}))

const dummyRequest = { nextUrl: { pathname: '/' } } as NextRequest
Expand All @@ -23,7 +20,19 @@ describe('handleFallback', () => {
expect(fallback).toBeCalledWith(dummyRequest, dummyEvent)
})

test('handle preflight', () => {
NextResponse.redirect = jest.fn()
handleFallback(
{ type: 'redirect', destination: '/foo/bar' },
{ ...dummyRequest, preflight: 1 } as unknown as NextRequest,
dummyEvent
)
expect(NextResponse.redirect).not.toBeCalled()
expect(NextResponse).toBeCalledWith(null)
})

test('passed redirect option', () => {
NextResponse.redirect = jest.fn()
handleFallback(
{ type: 'redirect', destination: '/foo/bar' },
dummyRequest,
Expand Down Expand Up @@ -51,6 +60,7 @@ describe('handleFallback', () => {
})

test('passed rewrite option', () => {
NextResponse.rewrite = jest.fn()
handleFallback(
{ type: 'rewrite', destination: '/foo/bar' },
dummyRequest,
Expand Down

0 comments on commit 4f77b2b

Please sign in to comment.