Code Monkey home page Code Monkey logo

Comments (9)

valerybugakov avatar valerybugakov commented on May 13, 2024 1

Same issue here. Any suggestion on how to resolve it?

from jest-mock-extended.

Toilal avatar Toilal commented on May 13, 2024 1

Maybe the cause if that jest property is not globally available in an ESM environement, please read this issue

jestjs/jest#9430

jest "global" property
This is not really a global - it's injected into the module scope. Since the module scope is gone in ESM, we need to move it somewhere. Adding it to import.meta seems natural - there's an option called initializeImportMeta which we can use.

EDIT: Solution here is to fetch it via import {jest} from '@jest/globals'. We might still add it via import.meta in the future, but this should be enough for now.

I'll give it a try and open a pull request if it's fix the issue.

from jest-mock-extended.

winfr34k avatar winfr34k commented on May 13, 2024

This seems like it's still an issue. We've updated our project to use ESMs and experience the same error message. I thought that the 2.0 release would be enough.

Is this related to jestjs/jest#11677?

from jest-mock-extended.

marchaos avatar marchaos commented on May 13, 2024

Not related. I'll take a look.

from jest-mock-extended.

viceice avatar viceice commented on May 13, 2024

It's the ways typescript exports in newer versions. for esm the export must be enumerable i think. Thats the only difference i've seen in the version diff.

from jest-mock-extended.

marchaos avatar marchaos commented on May 13, 2024

Can you test out version 2.0.2-beta2? That version has both commonjs and ESM modules so should work with both.

from jest-mock-extended.

winfr34k avatar winfr34k commented on May 13, 2024

@marchaos At least for me this doesn't change a thing:

 FAIL  tests/client/medium.spec.ts
  ● Test suite failed to run

    SyntaxError: The requested module 'jest-mock-extended' does not provide an export named 'mock'

      at Runtime.linkAndEvaluateModule (node_modules/jest-runtime/build/index.js:669:5)
☁  communityvi-frontend [update/jest-v27] ⚡  grep "mock" package.json
		"jest-mock-extended": "^2.0.2-beta2",
☁  communityvi-frontend [update/jest-v27] ⚡  grep "mock" package-lock.json
				"jest-mock-extended": "^2.0.2-beta2",
				"jest-mock": "^27.0.6"
				"jest-mock": "^27.0.6",
				"jest-mock": "^27.0.6",
				"jest-mock": "^27.0.6",
		"node_modules/jest-mock": {
			"resolved": "https://registry.npmjs.org/jest-mock/-/jest-mock-27.0.6.tgz",
		"node_modules/jest-mock-extended": {
			"resolved": "https://registry.npmjs.org/jest-mock-extended/-/jest-mock-extended-2.0.2-beta2.tgz",
		"node_modules/jest-mock/node_modules/@jest/types": {
		"node_modules/jest-mock/node_modules/@types/yargs": {
				"jest-mock": "^27.0.6",
				"jest-mock": "^27.0.6"
				"jest-mock": "^27.0.6",
				"jest-mock": "^27.0.6",
				"jest-mock": "^27.0.6",
		"jest-mock": {
			"resolved": "https://registry.npmjs.org/jest-mock/-/jest-mock-27.0.6.tgz",
		"jest-mock-extended": {
			"resolved": "https://registry.npmjs.org/jest-mock-extended/-/jest-mock-extended-2.0.2-beta2.tgz",
				"jest-mock": "^27.0.6",

from jest-mock-extended.

shrink avatar shrink commented on May 13, 2024

For anyone with the same issue, I've been unable to work out how to use the mock function because there seems to be some issue with how it's exported, but as a workaround, the deepMock method works in its place.

from jest-mock-extended.

Toilal avatar Toilal commented on May 13, 2024

I have opened a pull request that should solve the issue.

Note that jest-resolve actually doesn't support hybrid package.json (ESM + CJS) as node Conditional exports properties are NOT read here :

https://github.com/facebook/jest/blob/a20bd2c31e126fc998c2407cfc6c1ecf39ead709/packages/jest-resolve/src/shouldLoadAsEsm.ts#L74-L94

For extension-less imports (like dependencies), it only checks for type: 'module' property into package.json.

So, when importing jest-mock-extended inside a jest test, it will use CJS even if your try to implement an hybrid package. For more info about how to create an hybrid pattern, check this post : https://2ality.com/2019/10/hybrid-npm-packages.html

from jest-mock-extended.

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.