dark-hole
dark-hole
swallows(accepts) everything, and everything just disappears(gone). Like a blackhole.
dark-hole
is useful if you pretend to implement some interfaces but not actually implement them.
And you could trace everything that swallowed by dark-hole
, which is very useful for testing purpose.
Install
$ npm i dark-hole
Usage
const create trace } = // Create a blackhole which swallows everythingconst blackhole = const returnValue = blackholewhateverProperty // 1asAccessingArrayItem0 // 2, 3 // 3, 4destroyTheWorld // 5boooooooom // 6 // 7, 8// Nothing happens. Nothing. Without errors.
Trace accessing and invoking
// Create a tracer which could trace back upon time// to the very beginning of the `blackhole`// just like a time machineconst tracer = // `willBeCalledWith()` returns a new tracker afterwards// if there is a matchconst after4 = tracer try tracer catch err console // 'NO_MATCH' // It was not accessed immediately.
Only trace accessing
const after7 = after4 // No errors
Only trace function call
const end = after7 console// true// , if nothing happens afterwards
APIs
create() : Proxy
Returns a dark hole
trace(DarkHole) : Tracer
tracer.willBeCalledWith(options): Tracer
- accessor?
string | Array<string>
- thisArg?
any
Ifoptions
does not contain the'thisArg'
property, then it will match any this argument. Or it will do a exact match. - args?
Array<any>=[]
- immediately?
boolean
Returns Tracer
if there is a match.
Or an NO_MATCH
error will be thrown.
tracer.willBeAccessedBy(options): Tracer
- accessor
string | Array<string>
- immediately?
boolean
Returns Tracer
if there is a match.
Or an NO_MATCH
error will be thrown.