Comments (9)
Same issue here. Any suggestion on how to resolve it?
from jest-mock-extended.
Maybe the cause if that jest
property is not globally available in an ESM environement, please read this issue
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.
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.
Not related. I'll take a look.
from jest-mock-extended.
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.
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.
@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.
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.
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 :
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)
- Observable.of mock interface implementation HOT 2
- Option to have mock methods throw by default HOT 2
- description field for Custom Matcher should be optional HOT 2
- Mocks evaluate to `undefined` when used with expect.anything() or expect.any()
- how to define overridable default mock implementation HOT 3
- Doesn't mock special fn in prisma package
- `.calledWith` ignores plain objects as its condition HOT 2
- Support for TypeScript 5.0 HOT 1
- Required to use calledWith when using TypeScript HOT 2
- Typescript error when using @jest/globals
- Doesn't work if injectGlobals is false HOT 1
- The captor function causes type errors when used with `calledWith`.
- How to deep-compare objects with `calledWith`? HOT 1
- Cannot set mock return value on `toString`
- TypeError: Jest: a transform must export a `process` function.
- How to mock an external package with deepMock HOT 1
- How to compare mock to an object with jest HOT 2
- Extreme slow processing of mocks that are created via the mock() function
- Add support for Jest v30
- Type 'DeepNullable<K>' does not satisfy the constraint 'WeakKey' HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jest-mock-extended.