Socket
Socket
Sign inDemoInstall

spyn

Package Overview
Dependencies
0
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    spyn

Simple and safe spy tool for tests


Version published
Maintainers
1
Install size
6.19 kB
Created

Readme

Source

Spyn

Build Status

Safe and minimal spying tool for testing purposes.

Installation

npm install spyn --save-dev

Reference

Spy

Takes a function and returns a function that is being spied on.

const spiedFn = spy(sum)

spiedFn(1, 2) // => 3

There is also a optional configuration object which allows you to define what function call properties are stored in the calls array. By default it stores arguments and return values.

const spiedFn = spy(sum, {arguments: false, this: true})

spiedFn.call('thiz', 'a', 'b') // => 'ab'

calls(spiedFn) // => [{this: 'thiz', return: 'ab'}]

Calls

Takes a spy function and returns an array containing information of each call

const spiedFn = spy(multiply)

spiedFn(1,2)

calls(spiedFn) // => [{arguments: [1,2], return: 2}]

Original

Returns the original function of the spy.

const spiedFn = spy(divide)

spiedFn === divide // => false

original(spiedFn) === divide // => true

Usage

Spies tend to be used only in tests. They allow you to observe and automate the checking of function calls.

It is good practice to remove a spy when the test has completed. This prevents edge cases.

Tests

npm install && npm test

Example

Keywords

FAQs

Last updated on 03 Apr 2022

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