8000 🐛 Bug: chai-as-promised with top-level-await in setup file no longer applies · Issue #5392 · mochajs/mocha · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
🐛 Bug: chai-as-promised with top-level-await in setup file no longer applies #5392
Open
@perrin4869

Description

@perrin4869

Bug Report Checklist

  • I have read and agree to Mocha's Code of Conduct and Contributing Guidelines
  • I have searched for related issues and issues with the faq label, but none matched my issue.
  • I have 'smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, my usage of Mocha, or Mocha itself.
  • I want to provide a PR to resolve this

Expected

If you have a file setup.js:

import { use } from "chai";

use((await import("sinon-chai")).default);
use((await import("chai-as-promised")).default);

and you execute mocha with mocha --require "setup.js", chai should be able to make assertions on promises, etc

Actual

trying to do something like expect(Promise.resolve("foo")).to.become("foo")

will result in Error: Invalid Chai property: become. Did you mean "below"?

Minimal, Reproducible Example

Detailed above

Versions

mocha>=11.7.0, including 11.7.1

Additional Info

I am guessing it has to do with the recent change to use require, which doesn't support top level await. I don't have much insight into how require(ESM) works, but on mocha<11.7.0 the above snippet worked (probably because it was imported, thus allowing for top level await?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: in triagea maintainer should (re-)triage (review) this issuetype: buga defect, confirmed by a maintainer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0