Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Assert that your callback got called
JavaScript
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
examples
lib
test
.travis.yml
LICENSE
README.md
package.json

README.md

assert-called Build Status

Assert that your callback got called.

Installation

npm install assert-called

Usage

var cb = require('assert-called');

function notCalling(cb) {
}

function notCalled() {
}

process.nextTick(cb(function () {
  console.log('called');
}));

notCalling(cb(notCalled));

Will output:

called

/Users/maciej/dev/js/assert-called/lib/assert-called.js:26
    throw new assert.AssertionError({
          ^
AssertionError: 1 callback not called:
  notCalled
    at Object.<anonymous> (/Users/maciej/dev/js/assert-called/examples/called-and-not-called.js:13:12)
    at Module._compile (module.js:454:26)
    at Object.Module._extensions..js (module.js:472:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.runMain (module.js:497:10)
    at process.startup.processNextTick.process._tickCallback (node.js:325:13)

How it works

assert-called attaches a process.on('exit') listener to make sure that all registered callbacks are eventually called.

Something went wrong with that request. Please try again.