jest hangs indefinitely, runs no tests
This happens to me too but it’s intermittent, very frustrating though. I have discovered a workaround which is to run using the –runInBand flag, which just runs tests in the same thread: jest –runInBand
This happens to me too but it’s intermittent, very frustrating though. I have discovered a workaround which is to run using the –runInBand flag, which just runs tests in the same thread: jest –runInBand
Similar to what others have said, but instead of trying to mock the DOM yourself, just use JSDOM: // __mocks__/client.js import { JSDOM } from “jsdom” const dom = new JSDOM() global.document = dom.window.document global.window = dom.window Then in your jest config: “setupFiles”: [ “./__mocks__/client.js” ],
Since Babel 7 the Babel team switched to scoped packages, so you now have to use @babel/core instead of babel-core. But in essence, @babel/core is just a newer version of babel-core. This is done to make a better distinction which packages are official and which are third-party.
In case you are using a setupTests.js file you can import regenerator-runtime from there: // setupTests.js import ‘regenerator-runtime/runtime’ import Enzyme from ‘enzyme’ import EnzymeAdapter from ‘enzyme-adapter-react-16’ Enzyme.configure({ adapter: new EnzymeAdapter() }) Then you can import setupTests.js to every test file or better yet, in your package.json just add setupFilesAfterEnv to the jest config: // … Read more
As every test suite run its own environment, you can mock globals by just overwriting them. All global variables can be accessed by the global namespace: global.navigator = { onLine: true } The overwrite has only effects in your current test and will not effect others. This also a good way to handle Math.random or … Read more
Even though I have tried them separately, I haven’t tried them together (transform and transformIgnorePatterns). So this jest configuration solved my issue: “jest”: { “preset”: “ts-jest”, “testEnvironment”: “node”, “transform”: { “node_modules/variables/.+\\.(j|t)sx?$”: “ts-jest” }, “transformIgnorePatterns”: [ “node_modules/(?!variables/.*)” ] }, My mistakes were: Not using transform and transformIgnorePatterns together. And defining babel-jest as the transformer instead of … Read more
From my answer to another question, this can be simpler: The only requirement is to configure your test environment to Babel, and add the ECMAScript 6 transform plugin: Step 1: Add your test environment to .babelrc in the root of your project: { “env”: { “test”: { “plugins”: [“@babel/plugin-transform-modules-commonjs”] } } } Step 2: Install the … Read more
Also using Babel, Typescript and Jest. Had the same failure, driving me crazy for hours. Ended up creating a new babel.config.js file specifically for the tests. Had a large .babelrc that wasn’t getting picked up by jest no matter what i did to it. Main app still uses the .babelrc as this overrides babel.config.js files. … Read more