Comments (3)
+1
from esbuild-runner.
Can confirm, using esbuild-runner
with tests that need to jest.mock
imported functions will break things. If you want to quickly reproduce this problem you can setup any test that required mocking imported functions
// something.test.ts
import { importedFunction } from './otherFile'
jest.mock('./otherFile', () => ({
importedFunction: jest.fn().mockResolvedValue(true),
}))
from esbuild-runner.
any solution for this?
I replaced @swc/jest transformer with esbuild-runner/jest and jest.mock no longer works correctly
some.test.ts
import { myModule } from "@/someDir";
import { myFunction } from "@/myFunction";
jest.mock("@/someDir")
test("test1", () => {
(myModule as Jest.MockedFunction).mockImplementationOnce(() => Promise.resolve(true));
myFunction();
expect(myModule).toHaveBeenCalledTimes(1)
});
@/myFunction.ts
import { myModule } from "@/someDir";
export function myFunction() {
// other code...
myModule();
}
from esbuild-runner.
Related Issues (20)
- Incompatible with node-tap sourcemap support
- Allow package.json dependencies to be selectively transpiled / bundled HOT 1
- tslib required?
- Working with mocha and nyc HOT 6
- Benchmarks?
- `import.meta` not available in Jest HOT 2
- Sibling workspace module's node_modules should not be transpiled
- Correctly handle `require.main === module`
- Support esbuild-runner.config.cjs (or customizable esbuild-runner config file)
- paths in `Error.stack` "multiply" ...?
- passing pre-load packages like nodejs HOT 1
- Duplicate import in monorepo HOT 1
- JSX syntax extension is not currently enabled for Jest runner HOT 1
- Fails in jest 28 HOT 1
- Question / Request for documentation examples HOT 1
- `ERR_INVALID_URL_SCHEME`: `data:text/javascript,` is not supported like `ts-node`
- typescript check before run HOT 1
- New version release HOT 1
- Add `-v` or `--version` option to print version of esbuild-runner
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 esbuild-runner.