Skip to content

test(proxySet): add test for 'intersection' with Set-like object using 'forEach' fallback#1211

Open
sukvvon wants to merge 1 commit intopmndrs:mainfrom
sukvvon:test/proxySet-set-like-forEach
Open

test(proxySet): add test for 'intersection' with Set-like object using 'forEach' fallback#1211
sukvvon wants to merge 1 commit intopmndrs:mainfrom
sukvvon:test/proxySet-set-like-forEach

Conversation

@sukvvon
Copy link
Contributor

@sukvvon sukvvon commented Mar 7, 2026

Summary

  • Add test case for intersection with a Set-like object that has forEach but is not iterable
  • Covers previously uncovered hasForEach function (line 92) and forEach fallback path (lines 96-99) in src/vanilla/utils/proxySet.ts

Check List

  • pnpm run fix for formatting and linting code and docs

@vercel
Copy link

vercel bot commented Mar 7, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
valtio Ready Ready Preview, Comment Mar 7, 2026 7:39am

Request Review

@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 7, 2026

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 7, 2026

More templates

npm i https://pkg.pr.new/valtio@1211

commit: f6b5944


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
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
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
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

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds regression coverage for proxySet().intersection when given a non-iterable Set-like object that supports forEach, ensuring the hasForEach detection and forEach fallback path are exercised.

Changes:

  • Add a new test case for .intersection using a non-iterable Set-like object with forEach.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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
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. 😢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants