Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vitest-mock-extended

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vitest-mock-extended

Type safe mocking extensions for vitest, forked from jest-mock-extended

  • 2.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is vitest-mock-extended?

The vitest-mock-extended package provides utilities for creating mocks, spies, and stubs in the Vitest testing framework. It is designed to simplify the process of mocking dependencies and verifying interactions in unit tests.

What are vitest-mock-extended's main functionalities?

Creating Mocks

This feature allows you to create a mock object based on an interface or type. You can then define the behavior of the mock's methods and properties.

const { mock } = require('vitest-mock-extended');

const myMock = mock<MyInterface>();
myMock.someMethod.mockReturnValue('mocked value');

// Usage in a test
expect(myMock.someMethod()).toBe('mocked value');

Spying on Functions

This feature allows you to create a spy on an existing function. You can then define the behavior of the spied function and verify its interactions.

const { spyOn } = require('vitest-mock-extended');

const myObject = { myMethod: () => 'real value' };
const spy = spyOn(myObject, 'myMethod');
spy.mockReturnValue('spied value');

// Usage in a test
expect(myObject.myMethod()).toBe('spied value');
expect(spy).toHaveBeenCalled();

Stubbing Methods

This feature allows you to create a stub for a method. You can define the return value or behavior of the stubbed method.

const { stub } = require('vitest-mock-extended');

const myStub = stub<MyInterface>();
myStub.someMethod.returns('stubbed value');

// Usage in a test
expect(myStub.someMethod()).toBe('stubbed value');

Other packages similar to vitest-mock-extended

FAQs

Package last updated on 28 Aug 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

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc