Socket
Socket
Sign inDemoInstall

@vitest/expect

Package Overview
Dependencies
17
Maintainers
3
Versions
74
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @vitest/expect

Jest's expect matchers as a Chai plugin


Version published
Weekly downloads
4.5M
decreased by-15.46%
Maintainers
3
Install size
1.63 MB
Created
Weekly downloads
 

Package description

What is @vitest/expect?

The @vitest/expect package is a part of the Vitest testing framework, designed to work seamlessly with its ecosystem. It provides a powerful expectation library that allows developers to write assertions for their tests. This package is particularly useful for unit and integration testing, offering a wide range of matchers and utilities to test the behavior of JavaScript code.

What are @vitest/expect's main functionalities?

Basic Expectations

Allows for basic equality checks, useful for asserting that a value matches an expected result.

expect(value).toBe(42);

Object and Array Matching

Enables deep equality checks for objects and arrays, as well as checking for the presence of an item in an array.

expect(object).toEqual({ key: 'value' });
expect(array).toContain(item);

Asynchronous Testing

Facilitates testing of asynchronous operations, allowing assertions on resolved values of promises.

await expect(Promise.resolve('value')).resolves.toBe('value');

Mocking and Spies

Supports the creation of mock functions and spies, enabling the testing of function calls and their arguments.

const mockFunction = vi.fn();
expect(mockFunction).toHaveBeenCalledTimes(1);

Other packages similar to @vitest/expect

Readme

Source

@vitest/expect

Jest's expect matchers as a Chai plugin.

Usage

import * as chai from 'chai'
import { JestAsymmetricMatchers, JestChaiExpect, JestExtend } from '@vitest/expect'

// allows using expect.extend instead of chai.use to extend plugins
chai.use(JestExtend)
// adds all jest matchers to expect
chai.use(JestChaiExpect)
// adds asymmetric matchers like stringContaining, objectContaining
chai.use(JestAsymmetricMatchers)

FAQs

Last updated on 29 Sep 2023

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