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.37 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 16.0.0

  • Previously failed tests are now always run first.
  • A new concurrent reporter shows currently running tests, a test summary, a progress bar and estimated remaining time if possible.
  • Improved CLI colors.
  • jest <pattern> is now case-insensitive.
  • Added it.only, it.skip, test.only, test.skip and xtest.
  • Added --testNamePattern=pattern or -t <pattern> to run individual tests in test files.
  • Jest now warns for duplicate mock files.
  • Pressing a, o, p, q or enter while tests are running in the watch mode, the test run will be interrupted.
  • --bail now works together with --watch.
  • Added test.concurrent for concurrent async tests.
  • Jest now automatically considers files and tests with the .jsx extension.
  • Added jest.clearAllMocks to clear all mocks manually.
  • Rewrote Jest's snapshot implementation. jest-snapshot can now be more easily integrated into other test runners and used in other projects.
  • This requires most snapshots to be updated when upgrading Jest.
  • Objects and Arrays in snapshots are now printed with a trailing comma.
  • Function names are not printed in snapshots any longer to reduce issues with code coverage instrumentation and different Node versions.
  • Snapshots are now sorted using natural sort order.
  • Snapshots are not marked as obsolete any longer when using fit or when an error is thrown in a test.
  • Finished migration of Jasmine matchers to the new Jest matchers.
  • Pretty print toHaveBeenLastCalledWith, toHaveBeenCalledWith, lastCalledWith and toBeCalledWith failure messages.
  • Added toBeInstanceOf matcher.
  • Added toContainEqual matcher.
  • Added toThrowErrorMatchingSnapshot matcher.
  • Improved moduleNameMapper resolution.
  • Module registry fixes.
  • Fixed invocation of the setupTestFrameworkScriptFile script to make it easier to use chai together with Jest.
  • Removed react-native special case in Jest's configuration.
  • Added --findRelatedTests <fileA> <fileB> cli option to run tests related to the specified files.
  • Added jest.deepUnmock to babel-plugin-jest-hoist.
  • Added jest.runTimersToTime which is useful together with fake timers.
  • Improved automated mocks for ES modules compiled with babel.

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 03 Oct 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