1.2.0 • Published 4 years ago

dummee v1.2.0

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

dummee

Build Status codecov Maintainability

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'

when to use stubbing

install

yarn add --dev dummee or
npm install --save-dev dummee

also, this is handy:

dummee.stubIfTest

This function dummees 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.