Skip to content
This repository was archived by the owner on May 10, 2021. It is now read-only.

Commit 80062d3

Browse files
afzalsayed96FinnWoelm
authored andcommitted
Add test for res.redirect in API route
Test that res.redirect works in API routes. Documentation: https://nextjs.org/docs/api-routes/response-helpers
1 parent a9dade3 commit 80062d3

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default async function preview(req, res) {
2+
const { query } = req;
3+
const { to } = query;
4+
5+
res.redirect(`/redirectTest/${to}`);
6+
}

cypress/integration/default_spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,12 @@ describe("Preview Mode", () => {
535535
cy.url().should("include", "/previewTest/999");
536536
});
537537

538+
it("redirects to test page with res.redirect", () => {
539+
cy.visit("/api/redirect?to=999");
540+
541+
cy.url().should("include", "/redirectTest/999");
542+
});
543+
538544
it("redirects to static preview test page", () => {
539545
cy.visit("/api/enterPreviewStatic");
540546

0 commit comments

Comments
 (0)