Repository: honojs/hono
File: src/context.test.ts (TypeScript)

Code before:
        'Content-Type': 'text/plain',
      },
    })
    expect(res.headers.get('foo')).toBe('bar')
  })

  it('Should set cookie headers when re-assigning Response to `c.res`', () => {
    c.res = new Response(null)
    const res = new Response(null)
    res.headers.append('set-cookie', 'foo=bar; Path=/')
    res.headers.append('set-cookie', 'foo2=bar2; Path=/')
    c.res = res
    expect(c.res.headers.getSetCookie().length).toBe(2)
  })

  it('Should keep previous cookies in response headers', () => {
    c.res.headers.append('set-cookie', 'foo=bar; Path=/')
    setCookie(c, 'foo2', 'bar2', { path: '/' })

    const res = c.json({ message: 'Hello' })

    const cookies = res.headers.getSetCookie()

    console.debug('test cookies', cookies)

    expect(cookies.length).toBe(2)
  })
})

describe('Pass a ResponseInit to respond methods', () => {
  const req = new HonoRequest(new Request('http://localhost/'))
  let c: Context
  beforeEach(() => {
    c = new Context(req)
  })

  it('c.json()', async () => {
    const originalResponse = new Response('Unauthorized', {
      headers: {
        'content-type': 'text/plain',
        'x-custom': 'custom message',
      },
      status: 401,
    })
    const res = c.json(
      {
        message: 'Unauthorized',
      },
      originalResponse
    )
    expect(res.status).toBe(401)

Review comment (suggestion):
It's better to add tests to check the values as you wrote in your issue:

```ts
expect(cookies.includes('foo=bar; Path=/')).toBe(true)
expect(cookies.includes('foo2=bar2; Path=/')).toBe(true)
```

Code after:
        'Content-Type': 'text/plain',
      },
    })
    expect(res.headers.get('foo')).toBe('bar')
  })

  it('Should set cookie headers when re-assigning Response to `c.res`', () => {
    c.res = new Response(null)
    const res = new Response(null)
    res.headers.append('set-cookie', 'foo=bar; Path=/')
    res.headers.append('set-cookie', 'foo2=bar2; Path=/')
    c.res = res
    expect(c.res.headers.getSetCookie().length).toBe(2)
  })

  it('Should keep previous cookies in response headers', () => {
    c.res.headers.append('set-cookie', 'foo=bar; Path=/')
    setCookie(c, 'foo2', 'bar2', { path: '/' })
    const res = c.json({ message: 'Hello' })
    const cookies = res.headers.getSetCookie()
    expect(cookies.includes('foo=bar; Path=/')).toBe(true)
    expect(cookies.includes('foo2=bar2; Path=/')).toBe(true)
  })
})

describe('Pass a ResponseInit to respond methods', () => {
  const req = new HonoRequest(new Request('http://localhost/'))
  let c: Context
  beforeEach(() => {
    c = new Context(req)
  })

  it('c.json()', async () => {
    const originalResponse = new Response('Unauthorized', {
      headers: {
        'content-type': 'text/plain',
        'x-custom': 'custom message',
      },
      status: 401,
    })
    const res = c.json(
      {
        message: 'Unauthorized',
      },
      originalResponse
    )
    expect(res.status).toBe(401)
    expect(res.headers.get('content-type')).toMatch(/^application\/json/)
    expect(res.headers.get('x-custom')).toBe('custom message')
    expect(await res.json()).toEqual({
      message: 'Unauthorized',