ambar / es-jest Goto Github PK
View Code? Open in Web Editor NEWESM/React/TypeScript preprocessor for Jest, powered by esbuild.
License: MIT License
ESM/React/TypeScript preprocessor for Jest, powered by esbuild.
License: MIT License
As the title says, jest.mock doesn't work with es-jest. Adding above files in this repo and running the tests fail.
This totally blocks us. Can you please help?
// file myClass.ts
export default class MyClass {
doSomething() {
return 'foo'
}
}
// file test/myClass.test.ts
import MyClass from '../myClass';
jest.mock('../myClass');
const MockedMyClass = jest.mocked(MyClass, true);
// fails here on TypeError: MockedMyClass.mockImplementation is not a function
MockedMyClass.mockImplementation(() => ({
doSomething: () => 'bar',
}))
test('MyClass', () => {
const myClass = new MyClass();
expect(myClass.doSomething()).toEqual('bar')
})
Hey there. Thanks for the module. I believe a small change might be needed for Jest 28 compatibility, as I'm getting the current error:
FAIL test/jest/module-a.spec.js
โ Test suite failed to run
โ Invalid return value:
`process()` or/and `processAsync()` method of code transformer found at
"/Users/erin/grit/github.com/make-files/makefiles/test/pkg-js/npm/node_modules/es-jest/transform.js"
should return an object or a Promise resolving to an object. The object
must have `code` property with a string of processed code.
This error may be caused by a breaking change in Jest 28:
https://jestjs.io/docs/upgrading-to-jest28#transformer
Code Transformation Documentation:
https://jestjs.io/docs/code-transformation
at ScriptTransformer._buildTransformResult (node_modules/@jest/transform/build/ScriptTransformer.js:507:15)
at ScriptTransformer.transformSource (node_modules/@jest/transform/build/ScriptTransformer.js:628:17)
at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:765:40)
at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:822:19)
Could esbuild set as peerDependency instead of dependency? right now to be able to use it we need to use solutions like pnpm overrides
to force it to use the latest version of esbuild, this would also overrule #1
and thank you @ambar this solution just works, since I've been trying to use another solutions to use esbuild with jest and this library just works flawlessly
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.