Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tjoskar/simple-spy
Yet another spy library
https://github.com/tjoskar/simple-spy
spy testing-tools
Last synced: 29 days ago
JSON representation
Yet another spy library
- Host: GitHub
- URL: https://github.com/tjoskar/simple-spy
- Owner: tjoskar
- License: mit
- Created: 2015-08-16T19:18:03.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-12-07T05:55:04.000Z (about 1 month ago)
- Last Synced: 2024-12-12T15:38:35.722Z (about 1 month ago)
- Topics: spy, testing-tools
- Language: TypeScript
- Size: 1.5 MB
- Stars: 13
- Watchers: 3
- Forks: 3
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# simple-spy [![Coverage Status](https://coveralls.io/repos/github/tjoskar/simple-spy/badge.svg?branch=master)](https://coveralls.io/github/tjoskar/simple-spy?branch=master)
> yet another spy library
## Install
```
$ 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
```js
import { spy } from "simple-spy";const fun = (...args) => console.log(...args);
const funSpy = spy(fun);assert(funSpy.callCount === 0);
assert(funSpy.args.length === 0);funSpy("Hello Dexter Morgan"); // Output: Hello Dexter Morgan
assert(funSpy.callCount === 1);
assert(funSpy.args.length === 1);
assert(funSpy.args[0][0] === "Hello Dexter Morgan");funSpy.reset();
funSpy(1, 2, 3); // Output: 1 2 3
assert(funSpy.callCount === 1);
assert(funSpy.args.length === 1);
assert(funSpy.args[0].length === 3);
assert(funSpy.args[0][0] === 1);
assert(funSpy.args[0][1] === 2);
assert(funSpy.args[0][2] === 3);
```## API
### spy(fun)
#### fun
Type: `function`
## License
MIT © [Oskar Karlsson](https://tjoskar.dev)