https://github.com/kodedninja/fek
One ridiculously simple function to fake and spy
https://github.com/kodedninja/fek
Last synced: about 1 year ago
JSON representation
One ridiculously simple function to fake and spy
- Host: GitHub
- URL: https://github.com/kodedninja/fek
- Owner: kodedninja
- Created: 2019-03-03T14:54:44.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-03-03T18:38:15.000Z (over 7 years ago)
- Last Synced: 2025-04-30T10:23:02.185Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 2.93 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# fek
One ridiculously simple function to fake and spy.
## Installation
```
npm i fek
```
## Usage
```javascript
var test = require('tape')
var fake = require('fek')
test('spy', function (t) {
t.plan(4)
// spy
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')
// or fake
var f = fake()
f()
t.equal(f.callCount(), 1, 'it was called once')
})
```
## 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
- [jupiter/simple-mock](https://github.com/jupiter/simple-mock)