1.0.2 • Published 6 years ago

m.spy v1.0.2

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

m.spy

m(icro)spy is a simple test spy implementation written in es6+

travis dependencies coverage status linter

node version license minzip downloads

What is a test spy?

A test spy is a function that records arguments and thrown exceptions (if any) for all its calls.

Creating a spy as an anonymous function

The spy won’t do anything except record information about its calls. A common use case for this type of spy is testing how a function handles a callback:

const {spy} = require('m.spy')

test('calls listeners on event', () => {
  const callback = spy()
  const emitter = new EventEmitter()

  emitter.on('event', callback)
  emitter.emit('event')

  assertTrue(callback.called)
})

spy.called

Is true if the spy was called at least once.

spy.notCalled

Is true if the spy was not called.

spy.callCount

The number of recorded calls.

spy.args

Array of arguments received, spy.args0 is an array of arguments received in the first call.

spy.calledWith(arg1[, arg2, ...])

Returns true if spy was called at least once with the provided arguments. Can be used for partial matching, only provided arguments are checked against the actual arguments.

1.0.2

6 years ago

1.0.0

6 years ago

0.0.1

6 years ago

0.0.0-draft.0

6 years ago