Socket
Socket
Sign inDemoInstall

babel-plugin-jest-hoist

Package Overview
Dependencies
0
Maintainers
5
Versions
188
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/master/packages/babel-jes


Version published
Weekly downloads
23M
decreased by-2.83%
Maintainers
5
Install size
6.39 kB
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

jest 18.0.0

See https://jestjs.io/blog/2016/12/15/2016-in-jest

  • The testResultsProcessor function is now required to return the modified results.
  • Removed pit and mockImpl. Use it or mockImplementation instead.
  • Fixed re-running tests when --bail is used together with --watch.
  • pretty-format is now merged into Jest.
  • require('v8') now works properly in a test context.
  • Jest now clears the entire scrollback in watch mode.
  • Added expect.any, expect.anything, expect.objectContaining, expect.arrayContaining, expect.stringMatching.
  • Properly resolve snapshotSerializers, setupFiles, transform, testRunner and testResultsProcessor instead of using path.resolve.
  • --testResultsProcessor is now exposed through the cli.
  • Renamed --jsonOutputFile to --outputFile.
  • Added jest-editor-support for vscode and Nuclide integration.
  • Fixed test.concurrent unhandled promise rejections.
  • The Jest website is now auto-deployed when merging into main.
  • Updated testRegex to include test.js and spec.js files.
  • Fixes for babel-plugin-jest-hoist when using jest.mock with three arguments.
  • The JSON global in jest-environment-node now comes from the vm context instead of the parent context.
  • Jest does not print stack traces from babel any longer.
  • Fake timers are reset when FakeTimers.useTimers() is called.
  • Usage of Jest in watch mode can be hidden through JEST_HIDE_USAGE.
  • Added expect.assertions(number) which will ensure that a specified amount of assertions is made in one test.
  • Added .toMatchSnapshot(?string) feature to give snapshots a name.
  • Escape regex in snapshots.
  • jest-react-native was deprecated and now forwards react-native.
  • Added .toMatchObject matcher.
  • Further improve printing of large objects.
  • Fixed NaN% Failed in the OS notification when using --notify.
  • The first test run without cached timings will now use separate processes instead of running in band.
  • Added .toHaveProperty matcher.
  • Fixed Map/Set comparisons.
  • test.concurrent now works with --testNamePattern.

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

$ npm install babel-plugin-jest-hoist

Usage

.babelrc

{
  "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 15 Dec 2016

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