Skip to content
Open
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
18 changes: 18 additions & 0 deletions tests/proxySet.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,24 @@ describe('proxySet', () => {
expect(result).toEqual(proxySet([1, 9]))
})

it('.intersection with Set-like object that has forEach but is not iterable', () => {
const odds = proxySet([1, 3, 5, 7, 9])
const setLike = {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for this instead of native Set?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dai-shi Native Set and proxySet have Symbol.iterator, so they pass the isIterable check and skip the hasForEach path (line 92, 96-99). A Set-like object without Symbol.iterator is needed to cover the forEach fallback in asIterable.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I'll defer the review to copilot and @overthemike .

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the wait. I see what you're going for here. Is there a reason we're only testing for interesection?

size: 3,
has(v: number) {
return [1, 4, 9].includes(v)
},
keys() {
return [1, 4, 9].values()
},
forEach(cb: (v: number) => void) {
;[1, 4, 9].forEach(cb)
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The leading semicolon before the array literal is unnecessary here (the statement starts at the beginning of the block) and is the only occurrence of this pattern in the repo. Consider removing it to keep test style consistent and avoid confusing readers about ASI hazards that don’t apply in this context.

Suggested change
;[1, 4, 9].forEach(cb)
[1, 4, 9].forEach(cb)

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot doesn't know prettier. 😢

},
}
const result = odds.intersection(setLike)
expect(result).toEqual(proxySet([1, 9]))
})

// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/union#examples
it('.union', () => {
const evens = proxySet([2, 4, 6, 8])
Expand Down
Loading