Skip to content

Commit

Permalink
fix: add [Symbol.toStringTag] to Headers (#77)
Browse files Browse the repository at this point in the history
Co-authored-by: Artem Zakharchenko <[email protected]>
  • Loading branch information
jacob-ebey and kettanaito authored Mar 18, 2024
1 parent 67f3136 commit 539042b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/Headers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ describe('[Symbol.iterator]', () => {
})
})

describe('[Symbol.toStringTag]', () => {
it('returns "[object Headers]" when called', () => {
expect(new Headers().toString()).toEqual('[object Headers]')
})
})

describe('.keys()', () => {
it('returns the iterator with the header keys', () => {
const headers = new Headers({
Expand Down
5 changes: 4 additions & 1 deletion src/Headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export class Headers {
if (
['Headers', 'HeadersPolyfill'].includes(init?.constructor.name) ||
init instanceof Headers ||
(typeof globalThis.Headers !== 'undefined' && init instanceof globalThis.Headers)
(typeof globalThis.Headers !== 'undefined' &&
init instanceof globalThis.Headers)
) {
const initialHeaders = init as Headers
initialHeaders.forEach((value, name) => {
Expand All @@ -51,6 +52,8 @@ export class Headers {
}
}

[Symbol.toStringTag] = 'Headers';

[Symbol.iterator]() {
return this.entries()
}
Expand Down

0 comments on commit 539042b

Please sign in to comment.