From 60c8655858f3c62cf18c07075a5e9b595029f1c4 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Wed, 27 Mar 2024 14:10:43 +0100 Subject: [PATCH] typesave test --- frontend/src/pages/Guard.spec.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/frontend/src/pages/Guard.spec.ts b/frontend/src/pages/Guard.spec.ts index 0dde32b87a..c3b2ae8b2e 100644 --- a/frontend/src/pages/Guard.spec.ts +++ b/frontend/src/pages/Guard.spec.ts @@ -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' @@ -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(() => { @@ -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') } @@ -50,7 +53,7 @@ describe('global route guard', () => { }) it('does not redirect', async () => { - await guard({}) + await guard(pageContext) expect(redirect).not.toBeCalled() }) })