Skip to content
Discussion options

You must be logged in to vote

@adrian-kriegel The fetch spec dictates that redirects should reuse the original method and body to query the new resource and return the response as-is. For example, the following (adapted from your reproduction steps) will return status 404:

import { testApiHandler } from 'next-test-api-route-handler';

test('redirect', async () =>
{
  await testApiHandler(
    {
      handler: (req, res) => res.redirect(307, 'https://google.com/404'),
      test: async ({ fetch }) =>
      {
        const res = await fetch();
        // this succeeds
        expect(res.status).toBe(404);
      },
    },
  );
});

If you visit https://google.com/404 in your browser, you'll also see that you'll get a 404.

I…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Xunnamius
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
2 participants
Converted from issue

This discussion was converted from issue #763 on February 18, 2023 17:14.