emit-error
Emit error if callback is executed with a non-null 1st argument
example
var EventEmitter = require('events').EventEmitter,
emitError = require('..')
function callback (err) {
console.log('did not get an error')
}
function onError (err) {
console.error('got error: ' + err)
}
var emitter = new EventEmitter().on('error', onError)
var doSomething = emitError(emitter, callback)
doSomething(new Error('broke'))
doSomething()
output of above:
got error: Error: broke
did not get an error
toc
api
emitError
var emitError = require('emit-error')
var wrappedCb = emitError(emitter [, options, cb])
Returns a function that when called with a non-falsey first argument, will emit that value
as an error
event on the given event emitter
. If a falsey first argument is passed to the
generated function, or if an options
object is provided with a property of alwaysCall
set to
true
, then the provided callback cb
will be executed with all arguments passed to the
generated function.
If no callback cb
is provided, then the generated callback will simply emit error events when
called with a non-falsey 1st argument.
options:
- alwaysCall:
true
or false
- if true, the provided callback cb
will always be called, otherwise
it will only be called when a the first argument is falsey
testing
npm test [--dot | --spec] [--coverage]
options
--dot
- output test results as dots instead of tap--spec
- output test results as spec instead of tap--coverage
- display text cover report--testling
- run tests in browser via testling (cannot be used with --coverage and
expects both browserify and testling to be installed globally)
patterns
Only run test files matching a certain pattern by prefixing the
test command with grep=pattern
. Example:
grep=connect npm test --dot
html coverage report
Open it with npm run view-cover
or npm run vc