Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
53 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# 1.0.15 - 25 Apr 2024 | ||
# 1.0.15 - 27 Apr 2024 | ||
Feature: | ||
- add `redirect` function to `Context` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Elysia } from '../../src' | ||
|
||
import { describe, expect, it } from 'bun:test' | ||
import { req } from '../utils' | ||
|
||
describe('Response Headers', () => { | ||
it('handle redirect', async () => { | ||
const app = new Elysia().get('/', ({ redirect }) => redirect('/skadi')) | ||
|
||
const { headers, status } = await app.handle(req('/')) | ||
|
||
expect(status).toBe(301) | ||
// @ts-expect-error | ||
expect(headers.toJSON()).toEqual({ | ||
location: '/skadi' | ||
}) | ||
}) | ||
|
||
it('handle redirect status', async () => { | ||
const app = new Elysia().get('/', ({ redirect }) => | ||
redirect('/skadi', 302) | ||
) | ||
|
||
const { headers, status } = await app.handle(req('/')) | ||
|
||
expect(status).toBe(302) | ||
// @ts-expect-error | ||
expect(headers.toJSON()).toEqual({ | ||
location: '/skadi' | ||
}) | ||
}) | ||
|
||
it('add set.headers to redirect', async () => { | ||
const app = new Elysia().get('/', ({ redirect, set }) => { | ||
set.headers.alias = 'Abyssal Hunter' | ||
|
||
return redirect('/skadi') | ||
}) | ||
|
||
const { headers, status } = await app.handle(req('/')) | ||
|
||
expect(status).toBe(301) | ||
// @ts-expect-error | ||
expect(headers.toJSON()).toEqual({ | ||
location: '/skadi', | ||
alias: 'Abyssal Hunter' | ||
}) | ||
}) | ||
}) |