Sitelet https://github.com/chaijs/chai/pull/1861
Skip to content

fix: require callable iterators in iterable assertions - #1861

Merged
43081j merged 1 commit into
chaijs:mainfrom
20ns:fix/iterable-callable-iterator
Sep 23, 2026
Merged

43081j merged 1 commit into
chaijs:mainfrom
20ns:fix/iterable-callable-iterator

Conversation

@20ns

@20ns 20ns commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

expect({ [Symbol.iterator]: true }).to.be.iterable and assert.isIterable(...) currently pass, even though the value cannot be iterated. Passing it to .members() then throws a native TypeError from Array.from instead of an AssertionError.

Require Symbol.iterator to be a function in both iterable checks. This also makes .not.iterable accept these non-iterable objects and lets .members() reject either invalid input through its existing assertion guard.

Regression coverage includes truthy non-function iterator properties, negation, both member-comparison inputs, custom messages, a generator iterator, and checking iterability without calling the method. The six affected test cases fail against unchanged main and pass with the fix.

Validation:

  • pnpm run build
  • pnpm test: lint and formatting, 512 Node tests, 511 Chromium tests
  • pnpm run test-chrome --browsers firefox: Firefox could not start on this macOS 27.0 host. A standalone Playwright Firefox launch also times out before loading any test code.
  • pnpm run lint:types still fails with the same 601 existing diagnostics as unchanged main, after normalizing source positions.

AI assistance: Tested using Codex.

@20ns
20ns requested a review from a team as a code owner September 20, 2026 21:53
@43081j
43081j merged commit 8d42a17 into chaijs:main Sep 23, 2026
6 checks passed
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.

2 participants