Skip to content

Support use of t.end as callback #180

@timoxley

Description

@timoxley

Passing t.end as a callback is a nice feature of tape. It'll end the test & automatically check first arg for an error.

If one wants to use AVA's t.end as a callback though, firstly, it doesn't check for error arg, but secondly it will break due to references to this.

This would provide built-in support for node's errback pattern, echoing AVA's built-in support for promises.

Current implementation:

Test.prototype.end = function () {
    if (this.endCalled) {
        throw new Error('.end() called more than once');
    }

    this.endCalled = true;
    this.exit();
};

https://github.com/sindresorhus/ava/blob/7575ca82855da86e359a4ff8b17bb4588d626e8d/lib/test.js#L137-L144

All AVA Test methods face this issue, perhaps they should all be forcibly bound to the current instance, though t.end is probably by far the most useful one to have bound.

This may be is too much magic though, mainly raising as I noticed this didn't work when migrating my tape tests.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions