包详细信息

nanospy

ai4.8kMIT1.0.0

Spy and mock methods in tests with great TypeScript support

spy, mock, typescript, method

自述文件

Nano Spy

A tiny Node.js library to spy and mock methods in tests with great TypeScript support.

It will take only 6 KB in your node_modules and have 0 dependencies.

import { spyOn, restoreAll } from 'nanospy'

test.after.each(() => {
  restoreAll()
})

test('calls increase', () => {
  const spy = spyOn(counter, 'increase')
  counter.increase(5)
  assert.equal(spy.callCount, 1)
  assert.equal(spy.calls, [[5]])
})

Sponsored by Evil Martians

Docs

Read full docs here.

更新日志

Change Log

This project adheres to Semantic Versioning.

1.0

  • Added Spy#nextResolve() and Spy#nextReject().

0.5

  • Added Spy#onCall() for re-mocking (by Valery Zubkov).

0.4

  • Added Node.js 10 and 8 support.

0.3.2

  • Fixed keeping origin fn.length in spy.

0.3.1

  • Reduced package size.

0.3

  • Added spy() function.

0.2.1

  • Fixed docs.

0.2

  • Renamed Spy#reset() to Spy#restore().
  • Renamed resetSpies() to restoreAll().

0.1

  • Initial release.