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

Commit 6239191

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 d60c617 commit 6239191

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-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(`/shows/${to}`);
6+
}

cypress/integration/default_spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,14 @@ describe("API endpoint", () => {
526526
);
527527
});
528528
});
529+
530+
it("redirects with res.redirect", () => {
531+
cy.visit("/api/redirect?to=999");
532+
533+
cy.url().should("include", "/shows/999");
534+
cy.get("h1").should("contain", "Show #999");
535+
cy.get("p").should("contain", "Flash Gordon");
536+
});
529537
});
530538

531539
describe("Preview Mode", () => {

0 commit comments

Comments
 (0)