dummee
v1.2.0
Published
lightweight function stubbing for testing purposes
Downloads
6
Readme
dummee
Javascript function stubbing to test things.
- Zero deps
- Lightweight (312b unminified)
- Intuitive API
Inspired by ninos.
const dummee = require('dummee')
const stub1 = dummee()
stub1(1, 2) // => undefined
stub1.calls // => [{ args: [1, 2] }]
const stub2 = dummee((i, j) => i + j)
stub2(2, 3) // => 5
// updating the callback
stub2.cb = () => 'hey there'
stub2() // 'hey there'
install
yarn add --dev dummee
ornpm install --save-dev dummee
also, this is handy:
dummee.stubIfTest
This function dummee
s a function you pass to it only if current NODE_ENV
is 'test'
.
const { stubIfTest } = require('dummee')
function myFn(...) { ... }
// if process.env.NODE_ENV is 'test'
stubIfTest(myFn) // equivalent to dummee(myFn)
// if process.env.NODE_ENV is anything else
stubIfTest(myFn) // equivalent to myFn
This is very useful for my controlling functions called by the function I'm currently testing.
"That's a good trick" Anakin Skywalker
open to contributions
help is needed in:
- typescript definition and type check tests.