You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

testdouble

Package Overview
Dependencies
Maintainers
5
Versions
115
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

testdouble

A minimal test double library for TDD with JavaScript

3.20.2
latest
Source
npm
Version published
Weekly downloads
168K
-16.66%
Maintainers
5
Weekly downloads
 
Created

What is testdouble?

The testdouble npm package is a JavaScript library for creating test doubles, which are objects that stand in for real objects in your tests. It provides a simple and powerful API for creating mocks, stubs, and spies, making it easier to write unit tests for your code.

What are testdouble's main functionalities?

Creating a Test Double

This feature allows you to create a test double with specified methods. You can then define the behavior of these methods using `td.when` and `thenReturn`.

const td = require('testdouble');
const myDouble = td.object(['method1', 'method2']);
td.when(myDouble.method1()).thenReturn('value');
console.log(myDouble.method1()); // 'value'

Verifying Interactions

This feature allows you to verify that a method on a test double was called with specific arguments. This is useful for ensuring that your code interacts with dependencies as expected.

const td = require('testdouble');
const myDouble = td.object(['method1']);
myDouble.method1('arg1');
td.verify(myDouble.method1('arg1'));

Replacing Dependencies

This feature allows you to replace real dependencies with test doubles. This is useful for isolating the code under test and controlling the behavior of dependencies.

const td = require('testdouble');
const myModule = require('./myModule');
const dependency = td.replace('./dependency');
td.when(dependency.someMethod()).thenReturn('mocked value');
console.log(myModule.useDependency()); // 'mocked value'

Other packages similar to testdouble

Keywords

tdd

FAQs

Package last updated on 21 Mar 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