assertions-counter

0.0.1 • Public • Published

Assertions counter

Build Status

A simple assertions counter for asynchronous code testing

Installation

npm install assertions-counter

Usage

Example with mocha

It's convenient to count your assertions especially for mocked objects. In the example below a counter is called 2 times: first in the mocked worker.changeState method, second in the callback function for worker.cleanIO method. As the counter is equal to zero — mocha done function is called. Thus we match assertions number and test finish.

it('cleanIO', function (done) {
    var ac = new AssertionsCounter(2, done);

    var worker = {
            changeState: function (newState) {
                assert.instanceOf(newState, IdleState);
                ac.add();
            }
        },
        program = {
            cleanIO: function (callback) {
                callback(null);
            }
        },
        storage,
        state = new TerminatedState(worker, storage, program);

    state.cleanIO(function (err) {
        assert.isNull(err);

        ac.add();
    });
});

Readme

Keywords

Package Sidebar

Install

npm i assertions-counter

Weekly Downloads

1

Version

0.0.1

License

MIT

Last publish

Collaborators

  • dv