You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

@jest/expect

Package Overview
Dependencies
Maintainers
3
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jest/expect

This package extends `expect` library with `jest-snapshot` matchers. It exports `jestExpect` object, which can be used as standalone replacement of `expect`.


Version published
Weekly downloads
12M
decreased by-18.83%
Maintainers
3
Install size
17.5 MB
Created
Weekly downloads
 

Package description

What is @jest/expect?

@jest/expect is a part of the Jest testing framework that provides a set of matchers to assert different conditions in your tests. It allows you to write assertions in a readable and expressive way, making it easier to test your JavaScript code.

What are @jest/expect's main functionalities?

Basic Matchers

Basic matchers allow you to test simple values. In this example, `toBe` is used to check if the result of `2 + 2` is `4`.

expect(2 + 2).toBe(4);

Truthiness

Matchers for different types of truthiness. Here, `toBeNull` checks if the value is `null`.

expect(null).toBeNull();

Numbers

Matchers for comparing numbers. In this example, `toBeGreaterThan` checks if `4` is greater than `3`.

expect(4).toBeGreaterThan(3);

Strings

Matchers for strings. This example uses `not.toMatch` to check that the string 'team' does not contain the letter 'I'.

expect('team').not.toMatch(/I/);

Arrays and Iterables

Matchers for arrays and iterables. Here, `toContain` checks if the array contains the element 'Alice'.

expect(['Alice', 'Bob']).toContain('Alice');

Exceptions

Matchers for exceptions. This example uses `toThrow` to check if a function throws an error with the message 'error'.

expect(() => { throw new Error('error'); }).toThrow('error');

Other packages similar to @jest/expect

Readme

Source

@jest/expect

This package extends expect library with jest-snapshot matchers. It exports jestExpect object, which can be used as standalone replacement of expect.

The jestExpect function used in Jest. You can find its documentation on Jest's website.

FAQs

Package last updated on 20 Feb 2024

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc