Skip to content

fix: make .empty throw for async and generator functions - #1893

Merged
43081j merged 1 commit into
chaijs:mainfrom
NgoQuocViet2001:fix-empty-async-functions
Nov 3, 2026
Merged

43081j merged 1 commit into
chaijs:mainfrom
NgoQuocViet2001:fix-empty-async-functions

Conversation

@NgoQuocViet2001

Copy link
Copy Markdown
Contributor

.empty is meant to throw when given a function, but since v5 async, generator and async generator functions report tags like AsyncFunction. They miss the case 'function' branch and fall through to the object branch, and with no own enumerable keys the assertion passes:

async function fetchList() { return [1]; }
expect(await fetchList).to.be.empty; // passes; chai 4 threw ".empty was passed a function fetchList"
assert.isEmpty(function* () {}); // passes
expect(async function* () {}).to.not.be.empty; // "expected [AsyncGeneratorFunction] not to be empty"

This adds the three function tags to the existing function case, so every function kind throws .empty was passed a function <name> again. That matches chai 4 and what #1566 did for .a('function'). The message and behaviour for plain functions are unchanged.

Ran:

  • npm run lint: 0 errors (same 54 warnings as main)
  • npm run test-node after building index.js: 512 passing. The new cases in test/expect.js and test/assert.js fail on main (3 failing).

Checked: .empty / .not.empty on objects, arrays and strings behave as before.

@NgoQuocViet2001
NgoQuocViet2001 requested a review from a team as a code owner October 29, 2026 20:19
@43081j
43081j merged commit 2cd336d into chaijs:main Nov 3, 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