Socket
Socket
Sign inDemoInstall

vitest

Package Overview
Dependencies
0
Maintainers
4
Versions
343
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    vitest

Next generation testing framework powered by Vite


Version published
Weekly downloads
3.6M
decreased by-19.57%
Maintainers
4
Install size
23.6 MB
Created
Weekly downloads
 

Package description

What is vitest?

Vitest is a blazing fast unit test framework powered by Vite. It is designed to provide a delightful testing experience with features like native ES modules support, TypeScript support, and a rich API for running and organizing tests.

What are vitest's main functionalities?

Unit Testing

Vitest allows you to write and run unit tests for your JavaScript/TypeScript code. The example shows a simple test suite for a math operation.

import { describe, it, expect } from 'vitest';
describe('math', () => {
  it('should add numbers correctly', () => {
    expect(1 + 1).toBe(2);
  });
});

Mocking

Vitest provides a built-in mocking utility, allowing you to create mock functions and spy on their behavior.

import { vi } from 'vitest';
const mockFunction = vi.fn(() => 42);
mockFunction();
expect(mockFunction).toHaveBeenCalled();

Snapshot Testing

Vitest supports snapshot testing, which is useful for ensuring your UI does not change unexpectedly. It saves the 'snapshot' of the output and compares it against future test runs.

import { expect, test } from 'vitest';
test('snapshot test', () => {
  const user = { id: 1, name: 'John Doe' };
  expect(user).toMatchSnapshot();
});

Code Coverage

Vitest can generate code coverage reports to help you understand which parts of your codebase are covered by tests.

// Run Vitest with the --coverage flag to generate code coverage reports
// vitest run --coverage

Watch Mode

Vitest's watch mode re-runs tests when it detects changes in the test files or the corresponding source files, providing instant feedback during development.

// Run Vitest in watch mode using the --watch flag
// vitest --watch

Other packages similar to vitest

Readme

Source

vitest

NPM version

Next generation testing framework powered by Vite.

GitHub | Documentation

Keywords

FAQs

Last updated on 25 Apr 2024

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