1.0.0 • Published 5 years ago

fek v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

fek

One ridiculously simple function to fake and spy.

Installation

npm i fek

Usage

var test = require('tape')
var fake = require('fek')

test('spy', function (t) {
  t.plan(3)
  var f = fake(function (x) {
    return x * 2
  })

  f(2)

  t.equal(f.callCount(), 1, 'it was called once')
  t.deepEqual(f.lastArgs(), [2], 'with 2 as argument')
  t.equal(f.lastCall().returned, 4, 'returned 4')
})

API

spy = fake(fn)

Wraps fn in a spy. If there's no fn it fakes a function.

spy.calls()

Returns an array of calls with the following properties:

  • args: an array of arguments
  • returned: the value that was returned by fn

spy.callCount()

Returns the number of times the function was called.

spy.lastCall()

Returns the call object of the last call.

spy.lastArgs()

Returns the arguments of the last call.

spy.reset()

Resets all spy values.

See Also

1.0.0

5 years ago