diff --git a/tests/frontend/with-page-auth-required.test.tsx b/tests/frontend/with-page-auth-required.test.tsx
index ba23d7297..2c6d396e0 100644
--- a/tests/frontend/with-page-auth-required.test.tsx
+++ b/tests/frontend/with-page-auth-required.test.tsx
@@ -92,7 +92,11 @@ describe('with-page-auth-required csr', () => {
const ProtectedPage = withPageAuthRequired(MyPage, { returnTo: '/foo' });
render(, { wrapper: withUserProvider() });
- await waitFor(() => expect(window.location.assign).toHaveBeenCalledWith(expect.stringContaining('?returnTo=/foo')));
+ await waitFor(() =>
+ expect(window.location.assign).toHaveBeenCalledWith(
+ expect.stringContaining(`?returnTo=${encodeURIComponent('/foo')}`)
+ )
+ );
});
it('should use a custom login url', async () => {
@@ -117,7 +121,9 @@ describe('with-page-auth-required csr', () => {
render(, { wrapper: withUserProvider() });
await waitFor(() =>
- expect(window.location.assign).toHaveBeenCalledWith(expect.stringContaining('?returnTo=/foo/bar'))
+ expect(window.location.assign).toHaveBeenCalledWith(
+ expect.stringContaining(`?returnTo=${encodeURIComponent('/foo/bar')}`)
+ )
);
routerMock.basePath = basePath;
routerMock.asPath = asPath;
diff --git a/tests/helpers/with-page-auth-required.test.ts b/tests/helpers/with-page-auth-required.test.ts
index 3726eae06..1e6c9900a 100644
--- a/tests/helpers/with-page-auth-required.test.ts
+++ b/tests/helpers/with-page-auth-required.test.ts
@@ -12,7 +12,7 @@ describe('with-page-auth-required ssr', () => {
res: { statusCode, headers }
} = await get(baseUrl, '/protected', { fullResponse: true });
expect(statusCode).toBe(307);
- expect(headers.location).toBe('/api/auth/login?returnTo=/protected');
+ expect(decodeURIComponent(headers.location)).toBe('/api/auth/login?returnTo=/protected');
});
test('allow access to a page with a valid session', async () => {
@@ -32,7 +32,7 @@ describe('with-page-auth-required ssr', () => {
res: { statusCode, headers }
} = await get(baseUrl, '/protected', { fullResponse: true });
expect(statusCode).toBe(307);
- expect(headers.location).toBe('/api/auth/login?returnTo=/foo');
+ expect(decodeURIComponent(headers.location)).toBe('/api/auth/login?returnTo=/foo');
});
test('accept custom server-side props', async () => {
@@ -57,7 +57,7 @@ describe('with-page-auth-required ssr', () => {
res: { statusCode, headers }
} = await get(baseUrl, '/protected', { fullResponse: true });
expect(statusCode).toBe(307);
- expect(headers.location).toBe('/api/foo?returnTo=/protected');
+ expect(decodeURIComponent(headers.location)).toBe('/api/foo?returnTo=/protected');
delete process.env.NEXT_PUBLIC_AUTH0_LOGIN;
});