GithubHelp home page GithubHelp logo

Jest commonjs gives ReferenceError: Cannot access before initialization when jest.mock and exported class about swc_mut_cjs_exports HOT 2 OPEN

magic-akari avatar magic-akari commented on May 10, 2024
Jest commonjs gives ReferenceError: Cannot access before initialization when jest.mock and exported class

from swc_mut_cjs_exports.

Comments (2)

magic-akari avatar magic-akari commented on May 10, 2024 1

Could that ordering be an issue that causes the runtime error?

Yes. All import statements will be hoisted.
In fact, It's a bug of tsc. see microsoft/TypeScript#16166

Could a jest plugin like this hoisting of mock calls be related?

It's possible to hoist jest related methods.

I haven't tested it myself. Have you tried manually editing the statement order of the swc compiled files?
If it is feasible, It's better to send a feature request to https://github.com/swc-project/plugins/tree/main/packages/jest , since it is related to import hoisting and this repository focuses on the mutability of export.

from swc_mut_cjs_exports.

smvv avatar smvv commented on May 10, 2024

note: it seems that esbuild-jest is transforming the test source file using babel when the source code contains the string ock(: aelbore/esbuild-jest@e94d4c1#diff-a2a171449d862fe29692ce031981047d7ab755ae7f84c707aef80701b3ea0c80R34

from swc_mut_cjs_exports.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.