Socket
Socket
Sign inDemoInstall

ts-mockito

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-mockito

Mocking library for TypeScript


Version published
Weekly downloads
186K
decreased by-4.4%
Maintainers
1
Weekly downloads
 
Created

What is ts-mockito?

ts-mockito is a mocking library for TypeScript that allows developers to create mock objects and verify interactions with them. It is inspired by the Java library Mockito and provides a fluent API for creating and using mocks in unit tests.

What are ts-mockito's main functionalities?

Creating Mocks

This feature allows you to create a mock object of a class. The mock object can then be used to stub methods and verify interactions.

const myMock = mock(MyClass);

Stubbing Methods

This feature allows you to define the behavior of a mock object's method. In this example, when `someMethod` is called on `myMock`, it will return 'someValue'.

when(myMock.someMethod()).thenReturn('someValue');

Verifying Interactions

This feature allows you to verify that a method on a mock object was called a specific number of times. In this example, it verifies that `someMethod` was called exactly once.

verify(myMock.someMethod()).once();

Capturing Arguments

This feature allows you to capture the arguments passed to a mock object's method. In this example, it captures the arguments of the last call to `someMethod`.

const [arg1, arg2] = capture(myMock.someMethod).last();

Other packages similar to ts-mockito

Keywords

FAQs

Package last updated on 08 Jun 2020

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