Socket
Socket
Sign inDemoInstall

jest-matcher-utils

Package Overview
Dependencies
14
Maintainers
6
Versions
229
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    jest-matcher-utils

A set of utility functions for expect and related packages


Version published
Weekly downloads
35M
increased by1.38%
Maintainers
6
Install size
657 kB
Created
Weekly downloads
 

Package description

What is jest-matcher-utils?

The jest-matcher-utils package provides utility functions for creating custom Jest matchers. It is designed to help developers write their own matchers that integrate seamlessly with Jest's built-in expectation system, offering a way to extend Jest's assertion capabilities with custom logic. The utilities provided by this package include formatting values for error messages, comparing values, and generating matcher error messages.

What are jest-matcher-utils's main functionalities?

pretty-format

Formats any JavaScript value for pretty printing, which is useful for generating readable error messages in custom matchers.

const { prettyFormat } = require('jest-matcher-utils');
console.log(prettyFormat({ foo: 'bar' }));

matcherHint

Generates a hint string for a matcher, which can be used at the beginning of error messages to indicate which matcher failed.

const { matcherHint } = require('jest-matcher-utils');
console.log(matcherHint('.toBe'));

printExpected and printReceived

These functions format the expected and received values to be included in error messages, applying color highlighting to improve readability.

const { printExpected, printReceived } = require('jest-matcher-utils');
console.log(`Expected: ${printExpected(true)}
Received: ${printReceived(false)}`);

Other packages similar to jest-matcher-utils

Changelog

Source

28.1.1

Features

  • [jest] Expose Config type (#12848)
  • [@jest/reporters] Improve GitHubActionsReporters annotation format (#12826)
  • [@jest/types] Infer argument types passed to test and describe callback functions from each tables (#12885, #12905)

Fixes

  • [@jest/expect-utils] Fix deep equality of ImmutableJS OrderedMaps (#12899)
  • [jest-docblock] Handle multiline comments in parseWithComments (#12845)
  • [jest-mock] Improve spyOn error messages (#12901)
  • [jest-runtime] Correctly report V8 coverage with resetModules: true (#12912)
  • [jest-worker] Make JestWorkerFarm helper type to include methods of worker module that take more than one argument (#12839)

Chore & Maintenance

  • [docs] Updated docs to indicate that jest-environment-jsdom is a separate package #12828
  • [docs] Document the comments used by coverage providers #12835
  • [docs] Use docusaurus-remark-plugin-tab-blocks to format tabs with code examples (#12859)
  • [jest-haste-map] Bump walker version (#12324)

Readme

Source

jest-matcher-utils

This package's exports are most notably used by expect's this.utils.

Installation

To add this package as a dependency of a project, run either of the following commands:

  • npm install jest-matcher-utils
  • yarn add jest-matcher-utils

Exports (src/index.ts)

Functions

stringify highlightTrailingWhitespace printReceived printExpected printWithType ensureNoExpected ensureActualIsNumber ensureExpectedIsNumber ensureNumbers ensureExpectedIsNonNegativeInteger printDiffOrStringify diff pluralize getLabelPrinter matcherErrorMessage matcherHint

Types

MatcherHintOptions DiffOptions

Constants

EXPECTED_COLOR RECEIVED_COLOR INVERTED_COLOR BOLD_WEIGHT DIM_COLOR SUGGEST_TO_CONTAIN_EQUAL

FAQs

Last updated on 07 Jun 2022

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