Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
babel-plugin-jest-hoist
Advanced tools
Babel plugin to hoist `jest.disableAutomock`, `jest.enableAutomock`, `jest.unmock`, `jest.mock`, calls above `import` statements. This plugin is automatically included when using [babel-jest](https://github.com/facebook/jest/tree/master/packages/babel-jes
The babel-plugin-jest-hoist npm package is designed to work with Jest, a popular JavaScript testing framework. It allows Jest to hoist `jest.mock`, `jest.unmock`, `jest.enableAutomock`, `jest.disableAutomock`, `jest.useFakeTimers`, `jest.useRealTimers`, `jest.setMock`, and `jest.clearAllMocks` calls to the top of the file. This is necessary because Jest needs to isolate modules for mocking before they are used in tests, and doing so manually can be error-prone and tedious.
Hoisting jest.mock calls
Automatically hoists `jest.mock` calls to the top of the file, ensuring that modules are mocked before any other code execution.
"use strict";\njest.mock('moduleName');\nconsole.log('This is a test.');"
Hoisting jest.useFakeTimers calls
Automatically hoists `jest.useFakeTimers` calls to the top, allowing tests to use fake timers from the start.
"use strict";\njest.useFakeTimers();\nconsole.log('This is a test with fake timers.');"
Similar to babel-plugin-jest-hoist, babel-plugin-rewire allows for modifying module internals, such as variables and functions, for testing purposes. However, it focuses on enabling the rewire functionality rather than specifically working with Jest's global methods.
While ts-jest is a TypeScript preprocessor with source map support for Jest that lets you use Jest to test projects written in TypeScript, it includes features for handling module mocking and hoisting in a way that's compatible with TypeScript, offering a similar but TypeScript-focused functionality.
Babel plugin to hoist jest.disableAutomock
, jest.enableAutomock
, jest.unmock
, jest.mock
, calls above import
statements. This plugin is automatically included when using babel-jest.
$ yarn add --dev babel-plugin-jest-hoist
babel.config.js
(Recommended)module.exports = {
plugins: ['jest-hoist'],
};
$ babel --plugins jest-hoist script.js
require('@babel/core').transform('code', {
plugins: ['jest-hoist'],
});
FAQs
Babel plugin to hoist `jest.disableAutomock`, `jest.enableAutomock`, `jest.unmock`, `jest.mock`, calls above `import` statements. This plugin is automatically included when using [babel-jest](https://github.com/jestjs/jest/tree/main/packages/babel-jest).
The npm package babel-plugin-jest-hoist receives a total of 19,593,846 weekly downloads. As such, babel-plugin-jest-hoist popularity was classified as popular.
We found that babel-plugin-jest-hoist demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.