diff --git a/packages/wobe/src/Context.test.ts b/packages/wobe/src/Context.test.ts index 8afc4a1..b3a92da 100644 --- a/packages/wobe/src/Context.test.ts +++ b/packages/wobe/src/Context.test.ts @@ -1,4 +1,4 @@ -import { describe, expect, it, mock } from 'bun:test' +import { describe, expect, it, mock, spyOn } from 'bun:test' import { Context } from './Context' describe('Context', () => { @@ -58,6 +58,8 @@ describe('Context', () => { const request = new Request('https://example.com') const context = new Context(request) + const spyContextRes = spyOn(context.res, 'send') + context.redirect('https://example.com/test') expect(context.res.headers.get('Location')).toEqual( @@ -65,6 +67,9 @@ describe('Context', () => { ) expect(context.res.status).toEqual(302) + expect(spyContextRes).toHaveBeenCalledTimes(1) + expect(spyContextRes).toHaveBeenCalledWith('OK') + // Redirect permanently context.redirect('https://example.com/test2', 301) diff --git a/packages/wobe/src/Context.ts b/packages/wobe/src/Context.ts index 3266611..b90697b 100644 --- a/packages/wobe/src/Context.ts +++ b/packages/wobe/src/Context.ts @@ -51,6 +51,8 @@ export class Context { redirect(url: string, status = 302) { this.res.headers.set('Location', url) this.res.status = status + + this.res.send('OK') } /**