0.2.6 • Published 3 years ago

spyn v0.2.6

Weekly downloads
2
License
MIT
Repository
github
Last release
3 years ago

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

0.2.6

3 years ago

0.2.5

4 years ago

0.2.3

4 years ago

0.2.4

4 years ago

0.2.1

5 years ago

0.2.2

5 years ago

0.2.0

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.1

7 years ago

0.0.0

7 years ago