项目作者: tjoskar

项目描述 :
Yet another spy library
高级语言: TypeScript
项目地址: git://github.com/tjoskar/simple-spy.git
创建时间: 2015-08-16T19:18:03Z
项目社区:https://github.com/tjoskar/simple-spy

开源协议:MIT License

下载


simple-spy Coverage Status

yet another spy library

Install

  1. $ npm install --save-dev simple-spy

Usage

Live test the package and types in this Stackblitz container: https://stackblitz.com/edit/vitest-dev-vitest-ykic5d?file=test/basic.test.ts

  1. import { spy } from "simple-spy";
  2. const fun = (...args) => console.log(...args);
  3. const funSpy = spy(fun);
  4. assert(funSpy.callCount === 0);
  5. assert(funSpy.args.length === 0);
  6. funSpy("Hello Dexter Morgan"); // Output: Hello Dexter Morgan
  7. assert(funSpy.callCount === 1);
  8. assert(funSpy.args.length === 1);
  9. assert(funSpy.args[0][0] === "Hello Dexter Morgan");
  10. funSpy.reset();
  11. funSpy(1, 2, 3); // Output: 1 2 3
  12. assert(funSpy.callCount === 1);
  13. assert(funSpy.args.length === 1);
  14. assert(funSpy.args[0].length === 3);
  15. assert(funSpy.args[0][0] === 1);
  16. assert(funSpy.args[0][1] === 2);
  17. assert(funSpy.args[0][2] === 3);

API

spy(fun)

fun

Type: function

License

MIT © Oskar Karlsson