Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cookies): add .has in ResponseCookies #533

Merged
merged 4 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/mighty-nails-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@edge-runtime/cookies': fix
---

fix(cookies): add `.has` in `ResponseCookies`
4 changes: 4 additions & 0 deletions packages/cookies/src/response-cookies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ export class ResponseCookies {
return all.filter((c) => c.name === key)
}

has(name: string) {
return this._parsed.has(name)
}

/**
* {@link https://wicg.github.io/cookie-store/#CookieStore-set CookieStore#set} without the Promise.
*/
Expand Down
7 changes: 7 additions & 0 deletions packages/cookies/test/request-cookies.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ test('adding a cookie', () => {
])
})

test('cookies.has()', () => {
const headers = requestHeadersWithCookies('a=1; b=2')
const cookies = new RequestCookies(headers)
cookies.set('foo', 'bar')
expect(cookies.has('foo')).toBe(true)
})

test('cookies.toString()', () => {
const headers = requestHeadersWithCookies('a=1; b=2')
const cookies = new RequestCookies(headers)
Expand Down
7 changes: 7 additions & 0 deletions packages/cookies/test/response-cookies.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ test('options are not modified', async () => {
expect(options).toEqual({ maxAge: 10000 })
})

test('cookies.has()', () => {
const headers = new Headers()
const cookies = new ResponseCookies(headers)
cookies.set('foo', 'bar')
expect(cookies.has('foo')).toBe(true)
})

test('cookies.toString()', () => {
const cookies = new ResponseCookies(new Headers())
cookies.set({
Expand Down