Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jest-mock

Package Overview
Dependencies
Maintainers
7
Versions
238
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-mock

## API

  • 26.6.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
28M
decreased by-3.56%
Maintainers
7
Weekly downloads
 
Created

What is jest-mock?

The jest-mock package is a module for mocking classes and objects in JavaScript tests. It is part of the Jest testing framework but can be used independently. It allows developers to create mock functions, spy on function calls, and set return values or implementations for testing purposes.

What are jest-mock's main functionalities?

Creating Mock Functions

This feature allows you to create a mock function that can track calls, arguments, and return values. It can be used to test how a function is used without actually executing its logic.

const mockFn = jest.fn();

Mocking Return Values

With this feature, you can set a default return value for a mock function. This is useful when you want to test the behavior of code that depends on the return value of the function being mocked.

const mockFn = jest.fn().mockReturnValue('default value');

Mocking Modules

This feature allows you to mock entire modules, which is particularly useful when you want to isolate the module being tested from its dependencies.

jest.mock('moduleName', () => { return jest.fn(() => 'mocked module') });

Spying on Methods

Spying on methods enables you to observe and track calls to object methods without affecting their actual implementation. This is useful for verifying that methods are called with the correct arguments.

const spy = jest.spyOn(object, 'methodName');

Other packages similar to jest-mock

FAQs

Package last updated on 19 Oct 2020

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc