Skip to content

Commit

Permalink
typesave test
Browse files Browse the repository at this point in the history
  • Loading branch information
Mogge committed Mar 27, 2024
1 parent 1ea3c0c commit 60c8655
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions frontend/src/pages/Guard.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { redirect } from 'vike/abort'
import { PageContextServer } from 'vike/types'
import { describe, it, expect, vi, beforeEach } from 'vitest'

import { AUTH } from '#src/env'
Expand All @@ -9,7 +10,9 @@ import { guard } from './+guard'
AUTH.UNAUTHORIZED_REDIRECT_URI = 'https://some.uri'

vi.mock('vike/abort')
vi.mocked(redirect).mockResolvedValue()
vi.mocked(redirect).mockResolvedValue(new Error(''))

let pageContext: PageContextServer

describe('global route guard', () => {
beforeEach(() => {
Expand All @@ -19,7 +22,7 @@ describe('global route guard', () => {
describe('unauthenticated', () => {
it('throws and redirects', async () => {
try {
await guard({})
await guard(pageContext)
} catch (error) {
expect(redirect).toBeCalledWith('https://some.uri')
}
Expand Down Expand Up @@ -50,7 +53,7 @@ describe('global route guard', () => {
})

it('does not redirect', async () => {
await guard({})
await guard(pageContext)
expect(redirect).not.toBeCalled()
})
})
Expand Down

0 comments on commit 60c8655

Please sign in to comment.