Socket
Socket
Sign inDemoInstall

babel-plugin-jest-hoist

Package Overview
Dependencies
21
Maintainers
6
Versions
187
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    babel-plugin-jest-hoist

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/main/packages/babel-jest)


Version published
Weekly downloads
24M
decreased by-2.44%
Maintainers
6
Created
Weekly downloads
 

Package description

What is babel-plugin-jest-hoist?

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.

What are babel-plugin-jest-hoist's main functionalities?

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.');"

Other packages similar to babel-plugin-jest-hoist

Changelog

Source

29.4.0

Features

  • [expect, @jest/expect-utils] Support custom equality testers (#13654)
  • [jest-config, jest-worker] Use os.availableParallelism if available to calculate number of workers to spawn (#13738)
  • [@jest/globals, jest-mock] Add jest.replaceProperty() that replaces property value (#13496)
  • [jest-haste-map] ignore Sapling vcs directories (.sl/) (#13674)
  • [jest-resolve] Support subpath imports (#13705, #13723, #13777)
  • [jest-runtime] Add jest.isolateModulesAsync for scoped module initialization of asynchronous functions (#13680)
  • [jest-runtime] Add jest.isEnvironmentTornDown function (#13741)
  • [jest-test-result] Added skipped and focused status to FormattedTestResult (#13700)
  • [jest-transform] Support for asynchronous createTransformer (#13762)

Fixes

  • [jest-environment-node] Fix non-configurable globals (#13687)
  • [@jest/expect-utils] toMatchObject should handle Symbol properties (#13639)
  • [jest-mock] Fix mockReset and resetAllMocks undefined return value(#13692)
  • [jest-resolve] Add global paths to require.resolve.paths (#13633)
  • [jest-resolve] Correct node core module detection when using node: specifiers (#13806)
  • [jest-runtime] Support WASM files that import JS resources (#13608)
  • [jest-runtime] Use the scriptTransformer cache in jest-runner (#13735)
  • [jest-runtime] Enforce import assertions when importing JSON in ESM (#12755 & #13805)
  • [jest-snapshot] Make sure to import babel outside of the sandbox (#13694)
  • [jest-transform] Ensure the correct configuration is passed to preprocessors specified multiple times in the transform option (#13770)

Chore & Maintenance

  • [@jest/fake-timers] Update @sinonjs/fake-timers (#13612)
  • [docs] Improve custom puppeteer example to prevent worker warnings (#13619)

Readme

Source

babel-plugin-jest-hoist

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.

Installation

$ yarn add --dev babel-plugin-jest-hoist

Usage

module.exports = {
  plugins: ['jest-hoist'],
};

Via CLI

$ babel --plugins jest-hoist script.js

Via Node API

require('@babel/core').transform('code', {
  plugins: ['jest-hoist'],
});

FAQs

Last updated on 24 Jan 2023

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc