https://github.com/therealparmesh/snoop
Easy breezy test spies fo sheezy.
https://github.com/therealparmesh/snoop
Last synced: 8 months ago
JSON representation
Easy breezy test spies fo sheezy.
- Host: GitHub
- URL: https://github.com/therealparmesh/snoop
- Owner: therealparmesh
- License: mit
- Created: 2020-07-13T03:17:18.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-02-08T10:06:18.000Z (almost 3 years ago)
- Last Synced: 2024-11-08T19:18:17.250Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 367 KB
- Stars: 30
- Watchers: 2
- Forks: 2
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-list - snoop
README
# snoop 🎵
> Easy breezy test spies fo sheezy.

[](https://www.npmjs.com/package/snoop)
[](https://www.npmjs.com/package/snoop)
## Install
```sh
npm install --save-dev snoop
```
## Usage
Snoop collaborates with everyone.
### With [uvu](https://github.com/lukeed/uvu)
```js
import { snoop } from 'snoop';
import { test } from 'uvu';
import * as assert from 'uvu/assert';
const add = (a, b) => a + b;
test('add', () => {
const addFn = snoop(add);
const anotherAddFn = snoop(add);
addFn.fn(1, 1);
anotherAddFn.fn(1, 1);
addFn.fn(2, 2);
anotherAddFn.fn(2, 2);
assert.ok(addFn.called);
assert.not(addFn.notCalled);
assert.not(addFn.calledOnce);
assert.is(addFn.callCount, 2);
assert.equal(addFn.calls[0].arguments, [1, 1]);
assert.equal(addFn.calls[1].arguments, [2, 2]);
assert.is(addFn.calls[0].result, 2);
assert.is(addFn.calls[1].result, 4);
assert.not(addFn.firstCall.error);
assert.not(addFn.lastCall.error);
assert.ok(addFn.calledBefore(anotherAddFn));
assert.ok(addFn.calledAfter(anotherAddFn));
assert.ok(addFn.calledImmediatelyBefore(anotherAddFn));
assert.not(addFn.calledImmediatelyAfter(anotherAddFn));
});
test.run();
```