Skip to content

Improve t.throws output for mismatched constructor #1471

Closed
@sholladay

Description

@sholladay

Description

The output for a failed t.throws() assertion should be clearer when the actual and expected constructors do not match.

Currently, it simply says that there was an unexpected exception and shows the error object. It is not immediately clear at first glance that the constructor is what caused the assertion to fail.

Test Source

const foo = async () => {
    throw new TypeError('Uh oh');
};

test('foo() does stuff', async (t) => {
    await t.throws(foo(), RangeError);
});

Output

  Threw unexpected exception:

  TypeError {
    message: 'Uh oh',
  }

Environment

Node 8.1.4
npm 5.3.0
ava 0.21.0
darwin 16.6.0

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