Socket
Socket
Sign inDemoInstall

jest-mock

Package Overview
Dependencies
0
Maintainers
1
Versions
237
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-mock


Version published
Maintainers
1
Install size
750 B
Created

Package description

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

Changelog

Source

jest 20.0.0

  • New --projects option to run one instance of Jest in multiple projects at the same time. (#3400)
  • New multi project runner (#3156)
  • New --listTests flag. (#3441)
  • New --showConfig flag. (#3296)
  • New promise support for all expect matchers through .resolves and .rejects. (#3068)
  • New expect.hasAssertions() function similar to expect.assertions(). (#3379)
  • New this.equals function exposed to custom matchers. (#3469)
  • New valid-expect lint rule in eslint-plugin-jest. (#3067)
  • New HtmlElement pretty-format plugin. (#3230)
  • New Immutable pretty-format plugins. (#2899)
  • New test environment per file setting through @jest-environment in the docblock. (#2859)
  • New feature that allows every configuration option to be set from the command line. (#3424)
  • New feature to add custom reporters to Jest through reporters in the configuration. (#3349)
  • New feature to add expected and actual values to AssertionError. (#3217)
  • New feature to map code coverage from transformers. (#2290)
  • New feature to run untested code coverage in parallel. (#3407)
  • New option to define a custom resolver. (#2998)
  • New printing support for text and comment nodes in html pretty-format. (#3355)
  • New snapshot testing FAQ (#3425)
  • New support for custom platforms on jest-haste-map. (#3162)
  • New support for mocking native async methods. (#3209)
  • New guide on how to use Jest with any JavaScript framework. (#3243)
  • New translation system for the Jest website.
  • New collapsing watch mode usage prompt after first run. (#3078)
  • Breaking Change: Forked Jasmine 2.5 into Jest's own test runner and rewrote large parts of Jasmine. (#3147)
  • Breaking Change: Jest does not write new snapshots by default on CI. (#3456)
  • Breaking Change: Moved the typescript parser from jest-editor-support into a separate jest-test-typescript-parser package. (#2973)
  • Breaking Change: Replaced auto-loading of babel-polyfill with only regenerator-runtime, fixes a major memory leak. (#2755)
  • Fixed babel-jest to look up the babel field in package.json as a fallback.
  • Fixed jest-editor-support's parser to not crash on incomplete ASTs. (#3259)
  • Fixed jest-resolve to use is-builtin-module instead of resolve.isCore. (#2997)
  • Fixed jest-snapshot to normalize line endings in the serialize function. (#3002)
  • Fixed behavior of --silent flag. (#3003)
  • Fixed bug with watchers on macOS causing test to crash. (#2957)
  • Fixed CLI notify option not taking precedence over config option. (#3340)
  • Fixed detection of the npm client in SummaryReporter to support Yarn. (#3263)
  • Fixed done.fail not passing arguments (#3241)
  • Fixed fake timers to restore after resetting mocks. (#2467)
  • Fixed handling of babylon's parser options in jest-editor-support. (#3344)
  • Fixed Jest to properly cache transform results. (#3334)
  • Fixed Jest to use human-readable colors for Jest's own snapshots. (#3119)
  • Fixed jest-config to use UID for default cache folder. (#3380), (#3387)
  • Fixed jest-runtime to expose inner error when it fails to write to the cache. (#3373)
  • Fixed lifecycle hooks to make afterAll hooks operate the same as afterEach. (#3275)
  • Fixed pretty-format to run plugins before serializing nested basic values. (#3017)
  • Fixed return value of mocks so they can explicitly be set to return undefined. (#3354)
  • Fixed runner to run tests associated with snapshots when the snapshot changes. (#3025)
  • Fixed snapshot serializer require, restructured pretty-format. (#3399)
  • Fixed support for Babel 7 in babel-jest. (#3271)
  • Fixed testMatch to find tests in .folders. (#3006)
  • Fixed testNamePattern and testPathPattern to work better together. (#3327)
  • Fixed to show reject reason when expecting resolve. (#3134)
  • Fixed toHaveProperty() to use hasOwnProperty from Object (#3410)
  • Fixed watch mode's screen clearing. (#2959) (#3294)
  • Improved and consolidated Jest's configuration file resolution. (#3472)
  • Improved documentation throughout the Jest website.
  • Improved documentation to explicitly mention that snapshots must be reviewed. (#3203)
  • Improved documentation to make it clear CRA users don't need to add dependencies. (#3312)
  • Improved eslint-plugin-jest's handling of expect. (#3306)
  • Improved flow-coverage, eslint rules and test coverage within the Jest repository.
  • Improved printing of expect.assertions error. (#3033)
  • Improved Windows test coverage of Jest.
  • Refactored configs & transform (#3376)
  • Refactored reporters to pass individual Tests to reporters. (#3289)
  • Refactored TestRunner (#3166)
  • Refactored watch mode prompts. (#3290)
  • Deleted jest-file-exists. (#3105)
  • Removed Config type. (#3366)
  • Removed all usage of jest-file-exists. (#3101)
  • Adopted prettier on the Jest codebase.

FAQs

Last updated on 16 Mar 2016

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc